def upload_file(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) random_string = utilities.generate_random_string(30) # create upload object and save to db upload_obj = Upload(utilities.get_user_ip(), filename, random_string, datetime.now().strftime('%Y-%m-%d %H:%M'), utilities.get_date_time_now()) upload_obj.save_upload_to_db() print("saved") return "Your link is: " + random_string + "\n\n" + "Expires: " + utilities.get_date_time_now( ) return '''
def do_live(self, data): data = self.calibrator.calib(data) OK = True yowindow_file = self.params.get('live', 'yowindow', '') if yowindow_file: self.yowindow.write_file(yowindow_file, data) for template in eval(self.params.get('live', 'twitter', '[]')): if not self.do_twitter(template, data): OK = False for service in eval(self.params.get('live', 'services', '[]')): self.services[service].RapidFire(data, True) uploads = [] for template in eval(self.params.get('live', 'plot', '[]')): upload = self.do_plot(template) if upload and upload not in uploads: uploads.append(upload) for template in eval(self.params.get('live', 'text', '[]')): upload = self.do_template(template, data) if upload not in uploads: uploads.append(upload) if uploads: if not Upload.Upload(self.params, uploads): OK = False for file in uploads: os.unlink(file) return OK
def upload(): if request.method == 'POST': if 'file' not in request.files: return render_template('upload.html', lngs=Defines.lngs, msg='No file selected') filename = Upload.Upload(request.files['file']) if filename == '': return render_template('upload.html', lngs=Defines.lngs, msg='No file selected') extracted_text, summary, threshold = ProcessImage.ProcessImage( filename, request.form['lng']) render_text = '\n' for sentence, value in summary: # Format to be displayed in js on client render_text += '[`' + sentence + '`,' + str(value) + '],\n' return render_template('upload.html', lngs=Defines.lngs, msg='Successfully processed', threshold=threshold, extracted_text=render_text, img_src=filename) elif request.method == 'GET': return render_template('upload.html', lngs=Defines.lngs)
def __main__(): check_files_and_folders() socket = Socket.ServerSocket() connection = socket.Socket() sr = Server(connection, Cryptography.session_crypto(None), Registery.Registery(), Login.serverLogin(), Download.Download(), Upload.Upload(), List.List(), Read.Read(), Write.Write(), SessionKeyExchange.ServerSession(None), DACCommands.DACCommands(), Auditor.Auditor()) sr.Handler()
def upload(app, user, outcome, accept): '''Upload the results of a single run.''' reporting_url = user.reporting_url() if reporting_url and outcome.reports: # upload in the background, in case the network is slow import os if os.fork() > 0: return # compress reports in preparation for upload import Upload upload = Upload.Upload(outcome.reports) # collect headers from various contributors import SamplerConfig upload.headers['sampler-version'] = SamplerConfig.version upload.headers['accept'] = accept __add_headers(upload, app) __add_headers(upload, outcome) # install our special redirect hander import urllib2 import RedirectHandler redirect = RedirectHandler.RedirectHandler() urllib2.install_opener(urllib2.build_opener(redirect)) # post the upload and read server's response request = urllib2.Request(reporting_url, upload.body(), upload.headers) reply = urllib2.urlopen(request) # server may have requested a permanent URL change if redirect.permanent: # !!!: sanity check this before applying it # !!!: don't apply change if it is the same as the old value user.change_reporting_url(redirect.permanent) # server may have requested a sparsity change if reply.info().has_key('sampler-change-sparsity'): # !!!: sanity check this before applying it # !!!: don't apply change if it is the same as the old value user.change_sparsity(int(reply.info()['sampler-change-sparsity'])) # server may have posted a message for the user message = reply.read() if message and 'DISPLAY' in os.environ: base = reply.geturl() content_type = reply.info()['content-type'] del reply import ServerMessage dialog = ServerMessage.ServerMessage(base, content_type, message) dialog.run() # child is done; exit without fanfare os._exit(0)
def upload(app, reporting_url, outcome, accept): '''Upload the results of a single run.''' if outcome.reports: # upload in the background, in case the network is slow import os if os.fork() > 0: return # compress reports in preparation for upload import Upload upload = Upload.Upload(outcome.reports) # collect headers from various contributors import SamplerConfig upload.headers['sampler-version'] = SamplerConfig.version upload.headers['accept'] = accept __add_headers(upload, app) __add_headers(upload, outcome) # post the upload and read server's response request = urllib2.Request(reporting_url, upload.body(), upload.headers) reply = urllib2.urlopen(request) # server may have posted a message for the user message = reply.read() if message and 'DISPLAY' in os.environ: base = reply.geturl() content_type = reply.info()['content-type'] del reply import ServerMessage dialog = ServerMessage.ServerMessage(base, content_type, message) dialog.run() # child is done; exit without fanfare os._exit(0)
def do_tasks(self): sections = ['logged'] now = self.calib_data.before(datetime.max) if not now: now = datetime.now() threshold = now.replace(minute=(now.minute / 15) * 15, second=0, microsecond=0) last_update = self.params.get_datetime('hourly', 'last update') if (not last_update) or (last_update < threshold): # time to do hourly tasks sections.append('hourly') # set 12 hourly threshold threshold -= timedelta(hours=(threshold.hour - self.day_end_hour) % 12) last_update = self.params.get_datetime('12 hourly', 'last update') if (not last_update) or (last_update < threshold): # time to do 12 hourly tasks sections.append('12 hourly') # set daily threshold threshold -= timedelta(hours=(threshold.hour - self.day_end_hour) % 24) last_update = self.params.get_datetime('daily', 'last update') if (not last_update) or (last_update < threshold): # time to do daily tasks sections.append('daily') OK = True for section in sections: for template in eval(self.params.get(section, 'twitter', '[]')): if not self.do_twitter(template): OK = False for section in sections: yowindow_file = self.params.get(section, 'yowindow', '') if yowindow_file: self.yowindow.write_file(yowindow_file) break all_services = list() for section in sections: for service in eval(self.params.get(section, 'services', '[]')): if service not in all_services: all_services.append(service) for service in all_services: self.services[service].Upload(True) uploads = [] for section in sections: for template in eval(self.params.get(section, 'plot', '[]')): upload = self.do_plot(template) if upload and upload not in uploads: uploads.append(upload) for template in eval(self.params.get(section, 'text', '[]')): upload = self.do_template(template) if upload not in uploads: uploads.append(upload) if uploads: if not Upload.Upload(self.params, uploads): OK = False for file in uploads: os.unlink(file) if OK: for section in sections: self.params.set(section, 'last update', now.isoformat(' ')) return OK