Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still under building stage #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Downloads/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'karnikamit'
2 changes: 2 additions & 0 deletions Downloads/down.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[down_path]
path = "/home/karnikamit/Documents/keygen_ssh.txt"
23 changes: 23 additions & 0 deletions Downloads/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
__author__ = 'karnikamit'
import StringIO
from flask import send_file


class Download:
def __init__(self, path):
self.path = path
self.f_name = (self.path.split('.')[0]).split('/')[-1]
self.extn = self.path.split('.')[-1]

def download_file(self):
file_open = open(self.path, 'rb')
f = file_open.read()

# Downloading the file
strIO = StringIO.StringIO()
strIO.write(f)
strIO.seek(0)
file_open.close()
return send_file(strIO,
attachment_filename=self.f_name+'.'+self.extn,
as_attachment=True)
14 changes: 14 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__author__ = 'karnikamit'
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from routes import app
import sys


if __author__ == 'karnikamit':
sys.dont_write_bytecode = True
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(7000)
print 'Running on:', 7000
IOLoop.instance().start()
7 changes: 7 additions & 0 deletions routes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__author__ = 'karnikamit'
from flask import Flask
import os
app_route = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
app = Flask(__name__, template_folder=app_route+'/templates')
from routes import baseroutes

31 changes: 31 additions & 0 deletions routes/baseroutes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
__author__ = 'karnikamit'
from flask import jsonify, request, render_template
from routes import app
from Downloads.download import Download


@app.route('/try', methods=["POST"])
def api_try():
data = request.json
return jsonify(data)


@app.route('/get_file', methods=["POST", "GET"])
def download_file():
path = request.form['path']
do = Download(path)
try:
do.download_file()
return jsonify({"response": "success", "msg": "file successfully downloaded."})
except Exception, e:
return jsonify({"response": "failure", "msg": str(e)})


@app.route("/Download", methods=["GET"])
def download_api():
return render_template('download_form.html')


@app.route("/Upload", methods=["GET"])
def upload_api():
return render_template('upload_form.html')
14 changes: 14 additions & 0 deletions templates/download_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Download File
</title>
</head>
<body>
<h1> Download File </h1>
<form action=get_file method="Post">
file path: <input type="text" name="path">
</form>
</body>
</html>
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions uploads/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__author__ = 'karnikamit'



14 changes: 2 additions & 12 deletions upload.py → uploads/upload.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import tornado.httpserver, tornado.ioloop, tornado.options, tornado.web, os.path, random, string
from tornado.options import define, options

define("port", default=8888, help="run on the given port", type=int)

class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", IndexHandler),
(r"/upload", UploadHandler)
(r"/templates", UploadHandler)
]
tornado.web.Application.__init__(self, handlers)

Expand All @@ -25,11 +22,4 @@ def post(self):
output_file = open("uploads/" + final_filename, 'w')
output_file.write(file1['body'])
self.finish("file" + final_filename + " is uploaded")

def main():
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
main()