diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..7f0cdf9 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: /index.html + destination: /var/www/html/ +hooks: + BeforeInstall: + - location: scripts/install_dependencies + timeout: 300 + runas: root + - location: scripts/start_server + timeout: 300 + runas: root + ApplicationStop: + - location: scripts/stop_server + timeout: 300 + runas: root + diff --git a/manager.py b/manager.py index 48e7fdc..df04aa1 100644 --- a/manager.py +++ b/manager.py @@ -4,8 +4,8 @@ from filesystem import Folder, File from action import * from flask import request -from os import error - +from flask import send_file +#from os import error app = Flask(__name__) app.config.update( DEBUG=True, @@ -25,7 +25,11 @@ def index(path=''): context = my_file.apply_action(View) folder = Folder(app.config['FILES_ROOT'], my_file.get_path()) if context == None: - return render_template('file_unreadable.html', folder=folder) + + raw_file = my_file.path + + return send_file(raw_file) + return render_template('file_view.html', text=context['text'], file=my_file, folder=folder) @app.route('/search', methods=['POST']) diff --git a/manager.py~ b/manager.py~ new file mode 100644 index 0000000..99992e3 --- /dev/null +++ b/manager.py~ @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +import os +from flask import Flask, render_template, redirect, request +from filesystem import Folder, File +from action import * +from flask import request +from os import error + +app = Flask(__name__) +app.config.update( + DEBUG=True, + FILES_ROOT=os.path.dirname(os.path.abspath(__file__)), +) + +@app.route('/') +@app.route('/files/') +def index(path=''): + path_join = os.path.join(app.config['FILES_ROOT'], path) + if os.path.isdir(path_join): + folder = Folder(app.config['FILES_ROOT'], path) + folder.read() + return render_template('folder.html', folder=folder) + else: + my_file = File(app.config['FILES_ROOT'], path) + context = my_file.apply_action(View) + folder = Folder(app.config['FILES_ROOT'], my_file.get_path()) + if context == None: + + raw_file = my_file.path + + return send_file(raw_file) + + return render_template('file_view.html', text=context['text'], file=my_file, folder=folder) + +@app.route('/search', methods=['POST']) +def search(): + q = request.form['q'] + return render_template('search.html', request = q) + +@app.route('/new_directory', methods=["POST"]) +@app.route('//new_directory', methods=["POST"]) +def create_directory(path = "/"): + dirname = request.form["new_directory_name"] + directory_root = request.form["directory_root"] + full_path = os.path.join(directory_root, dirname) + try: + os.mkdir(full_path) + except error: + pass + return redirect('/files/' + directory_root) + + + +if __name__ == '__main__': + app.run(host="0.0.0.0") diff --git a/test_files/They said India doesn't innovate...-oQEFO393cd0.mp4 b/test_files/They said India doesn't innovate...-oQEFO393cd0.mp4 new file mode 100644 index 0000000..3ff7e79 Binary files /dev/null and b/test_files/They said India doesn't innovate...-oQEFO393cd0.mp4 differ diff --git a/test_files/aman.jpg b/test_files/aman.jpg new file mode 100644 index 0000000..545f46a Binary files /dev/null and b/test_files/aman.jpg differ diff --git a/test_files/archi.png b/test_files/archi.png new file mode 100644 index 0000000..a5614c8 Binary files /dev/null and b/test_files/archi.png differ diff --git a/test_files/archi.svg b/test_files/archi.svg new file mode 100644 index 0000000..0952863 --- /dev/null +++ b/test_files/archi.svg @@ -0,0 +1,4 @@ + +Different Parts of your Gmail37.53%442.243318604221.1153196221.90%410.782349104357.01484439320.93%332.021558526387.14719115139.64%217.347782734228.6112630640.00%331.191630918146.850000291Different Parts of your GmailInboxSentImportantArchivedTrashed \ No newline at end of file diff --git a/test_files/dream_career.jpg b/test_files/dream_career.jpg new file mode 100644 index 0000000..4d0ae42 Binary files /dev/null and b/test_files/dream_career.jpg differ diff --git a/test_files/fv.png b/test_files/fv.png new file mode 100644 index 0000000..fc65fee Binary files /dev/null and b/test_files/fv.png differ diff --git a/test_files/hello.mp3 b/test_files/hello.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test_files/honey1.png b/test_files/honey1.png new file mode 100644 index 0000000..0f54d19 Binary files /dev/null and b/test_files/honey1.png differ diff --git a/test_files/honey1.svg b/test_files/honey1.svg new file mode 100644 index 0000000..2edd1d2 --- /dev/null +++ b/test_files/honey1.svg @@ -0,0 +1,4 @@ + +Browser usage evolution (in %)0.00.04.04.08.08.012.012.016.016.020.020.024.024.028.028.032.032.036.036.01234Browser usage evolution (in %)012.4076923077504.11538461511167.503846154490.38675213720322.6504.11538461530477.696153846504.115384615412632.792307692339.371794872712.4076923077408.01495726516167.503846154421.743589744222322.6202.085470085312477.696153846339.371794872436632.7923076929.88461538462ChromeFirefox \ No newline at end of file diff --git a/test_files/image-21.jpg b/test_files/image-21.jpg new file mode 100644 index 0000000..e52d4ee Binary files /dev/null and b/test_files/image-21.jpg differ diff --git a/test_files/life.jpg b/test_files/life.jpg new file mode 100644 index 0000000..df99a58 Binary files /dev/null and b/test_files/life.jpg differ diff --git a/test_files/savefig.py b/test_files/savefig.py new file mode 100644 index 0000000..bc56f1a --- /dev/null +++ b/test_files/savefig.py @@ -0,0 +1,65 @@ +import os +import matplotlib.pyplot as plt + +def save(path, ext='png', close=True, verbose=True): + """Save a figure from pyplot. + Parameters + ---------- + path : string + The path (and filename, without the extension) to save the + figure to. + ext : string (default='png') + The file extension. This must be supported by the active + matplotlib backend (see matplotlib.backends module). Most + backends support 'png', 'pdf', 'ps', 'eps', and 'svg'. + close : boolean (default=True) + Whether to close the figure after saving. If you want to save + the figure multiple times (e.g., to multiple formats), you + should NOT close it in between saves or you will have to + re-plot it. + verbose : boolean (default=True) + Whether to print information about when and where the image + has been saved. + """ + + # Extract the directory and filename from the given path + directory = os.path.split(path)[0] + filename = "%s.%s" % (os.path.split(path)[1], ext) + if directory == '': + directory = '.' + + # If the directory does not exist, create it + if not os.path.exists(directory): + os.makedirs(directory) + + # The final path to save to + savepath = os.path.join(directory, filename) + + if verbose: + print("Saving figure to '%s'..." % savepath), + + # Actually save the figure + plt.savefig(savepath) + + # Close it + if close: + plt.close() + + if verbose: + print("Done") + + + +import numpy as np +import matplotlib.pyplot as plt + +# Make a quick sin plot +x = np.linspace(5, 10, 100) +y = np.sin(x) +plt.plot(x, y) +plt.xlabel("Time") +plt.ylabel("Amplitude") + +# Save it in png and svg formats +save("signal", ext="png", close=False, verbose=True) +save("signal", ext="svg", close=True, verbose=True) diff --git a/test_files/signal.svg b/test_files/signal.svg new file mode 100644 index 0000000..e8c8b3a --- /dev/null +++ b/test_files/signal.svg @@ -0,0 +1,801 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_files/url.png b/test_files/url.png new file mode 100644 index 0000000..5f67914 Binary files /dev/null and b/test_files/url.png differ