def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return save_message = 'ok' project_name = self.request.get('project-name') project_visible_to_owner_only = ( self.request.get('project-visible-to-owner-only') == 'on') if (project_name == '' or project_name == None): save_message = 'No project name provided' else: project = Project( name=project_name, owner=UserManager.get_email(), visible_to_owner_only=project_visible_to_owner_only, secret=base64.b64encode(os.urandom(48))) project.put() template = JINJA_ENVIRONMENT.get_template( 'templates/_endpoints/project-create.json') self.response.write(template.render({"message": save_message}))
def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return save_message = 'ok' project_name = self.request.get('project-name') project_visible_to_owner_only = (self.request.get( 'project-visible-to-owner-only') == 'on') if (project_name == '' or project_name == None): save_message = 'No project name provided' else: project = Project( name=project_name, owner=UserManager.get_email(), visible_to_owner_only=project_visible_to_owner_only, secret=base64.b64encode(os.urandom(48)) ) project.put() template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/project-create.json') self.response.write(template.render({ "message": save_message }))
def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return save_message = 'ok' project_key_string = self.request.get('project-key') project_name = self.request.get('project-name') project_visible_to_owner_only = ( self.request.get('project-visible-to-owner-only') == 'on') if (project_key_string == '' or project_key_string == None): save_message = 'No project key provided' else: project = Project.get_by_id(int(project_key_string)) if project == None: save_message = 'No project found' else: if UserManager.get_user_has_privilege_for_operation(project): project.name = project_name project.visible_to_owner_only = project_visible_to_owner_only project.put() else: save_message = 'Permission denied.' template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') self.response.write(template.render({ "message": save_message }))
def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return save_message = 'ok' project_key_string = self.request.get('project-key') project_name = self.request.get('project-name') project_visible_to_owner_only = ( self.request.get('project-visible-to-owner-only') == 'on') if (project_key_string == '' or project_key_string == None): save_message = 'No project key provided' else: project = Project.get_by_id(int(project_key_string)) if project == None: save_message = 'No project found' else: if UserManager.get_user_has_privilege_for_operation(project): project.name = project_name project.visible_to_owner_only = project_visible_to_owner_only project.put() else: save_message = 'Permission denied.' template = JINJA_ENVIRONMENT.get_template( 'templates/_endpoints/action-update.json') self.response.write(template.render({"message": save_message}))
def post (self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return save_message = 'ok' user_email = self.request.get('user-email') if (user_email == '' or user_email == None): save_message = 'No email address provided.' elif (UserManager.get_user_by_email_address(user_email) == None): save_message = 'User does not exist.' else: projects_to_reassign = Project.query().filter(Project.owner==user_email) to_update = [] for project in projects_to_reassign: project.owner = UserManager.get_email() to_update.append(project) if len(to_update) > 0: ndb.put_multi(to_update) user = UserManager.get_user_by_email_address(user_email) user.key.delete() template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') self.response.write(template.render({ "message": save_message }))
def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return delete_message = 'ok' project_key_string = self.request.get('project-key') if (project_key_string == '' or project_key_string == None): delete_message = 'No project key provided' else: project = Project.get_by_id(int(project_key_string)) if UserManager.get_user_has_privilege_for_operation(project): project_key = ndb.Key(Project, project.key.integer_id()) actions = Action.query(ancestor=project_key) # Start with the project to_delete = [project.key] # No find all its actions for action in actions: # Add those to the list to_delete.append(action.key) # Now get all the action details action_detail_key = ndb.Key( Project, project.key.integer_id(), Action, action.key.integer_id() ) action_details = ActionDetail.query(ancestor=action_detail_key) for action_detail in action_details: to_delete.append(action_detail.key) ndb.delete_multi(to_delete) else: delete_message = 'Permission denied.' template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') self.response.write(template.render({ "message": delete_message }))
def post(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return delete_message = 'ok' project_key_string = self.request.get('project-key') if (project_key_string == '' or project_key_string == None): delete_message = 'No project key provided' else: project = Project.get_by_id(int(project_key_string)) if UserManager.get_user_has_privilege_for_operation(project): project_key = ndb.Key(Project, project.key.integer_id()) actions = Action.query(ancestor=project_key) # Start with the project to_delete = [project.key] # No find all its actions for action in actions: # Add those to the list to_delete.append(action.key) # Now get all the action details action_detail_key = ndb.Key(Project, project.key.integer_id(), Action, action.key.integer_id()) action_details = ActionDetail.query( ancestor=action_detail_key) for action_detail in action_details: to_delete.append(action_detail.key) ndb.delete_multi(to_delete) else: delete_message = 'Permission denied.' template = JINJA_ENVIRONMENT.get_template( 'templates/_endpoints/action-update.json') self.response.write(template.render({"message": delete_message}))
def get(self, key): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return project = Project.get_by_id(int(key)) if project == None: self.redirect('/') return if not UserManager.get_user_has_privilege_for_operation(project): self.redirect('/') return project_key = ndb.Key(Project, int(key)) template_path = 'templates/project/action.html' data = { 'project_key': key, 'project_secret': project.secret, 'logs': Log.query(ancestor=project_key).order(-Log.date).fetch(5), 'actions': Action.query(ancestor=project_key).order(Action.name), 'action_upload_url': blobstore.create_upload_url('/action/import'), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'sections': [{ "name": "Projects", "url": "/project/list" }, { "name": project.name }] } template = JINJA_ENVIRONMENT.get_template(template_path) self.response.write(template.render(data))
def get(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return template = JINJA_ENVIRONMENT.get_template('templates/project/project.html') self.response.write(template.render({ 'projects': Project.query(), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'sections': [{ "name": "Projects" }] }))
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') project_secret = self.request.get('secret') project = Project.query().filter(Project.secret==project_secret).get() if (project == None): self.response.write(template.render({ "message": "No secret provided" })) return self.response.write(template.render({ "message": blobstore.create_upload_url('/action/import') }))
def get(self): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return template = JINJA_ENVIRONMENT.get_template( 'templates/project/project.html') self.response.write( template.render({ 'projects': Project.query(), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'sections': [{ "name": "Projects" }] }))
def post(self): key = self.request.get('key') data = self.request.get('data') if (key == None or data == None): return # We don't need a try here, because it's already been checked in the # import handler by this point. data_json = json.loads(data) trace = Trace.get_by_id(int(key)) if 'secret' not in data_json: return secret = data_json['secret'] project = Project.query().filter(Project.secret==secret).get() if (project == None): return if (trace == None): return @ndb.transactional(xg=True) def process_trace(project, trace, data_json): blob_reader = blobstore.BlobReader(trace.file_key) action_details_imported = TraceProcessor().process(project, blob_reader.read(), trace, data_json) # Tidy up the trace file if needed. if trace.delete_trace_after_import: blobstore.delete(trace.file_key) trace.key.delete() return action_details_imported action_details_imported = process_trace(project, trace, data_json)
def get(self, key): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return project = Project.get_by_id(int(key)) if project == None: self.redirect('/') return if not UserManager.get_user_has_privilege_for_operation(project): self.redirect('/') return project_key = ndb.Key(Project, int(key)) template_path = 'templates/project/action.html' data = { 'project_key': key, 'project_secret': project.secret, 'logs': Log.query(ancestor=project_key).order(-Log.date).fetch(5), 'actions': Action.query(ancestor=project_key).order(Action.name), 'action_upload_url': blobstore.create_upload_url('/action/import'), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'sections': [{ "name": "Projects", "url": "/project/list" },{ "name": project.name }] } template = JINJA_ENVIRONMENT.get_template(template_path) self.response.write(template.render(data))
def get(self): secret = self.request.get('secret') labels = self.request.get('labels') trace_key = self.request.get('trace') if (trace_key == ''): self.response.write('no trace key') return trace = Trace.get_by_id(int(trace_key)) if (secret == ''): self.response.write("no secret") return if (trace == None): self.response.write("no trace") return project = Project.query().filter(Project.secret==secret).get() if (project == None): self.response.write("no project") return labels_list = labels.split(',') labels_list_stringified = '"' + '","'.join(labels_list) + '"' if (labels == ''): labels_list_stringified = '' data = '{"secret":"' + secret + '", "labels": [' + labels_list_stringified + ']}' data_json = json.loads(data) blob_reader = blobstore.BlobReader(trace.file_key) TraceProcessor().process(project, blob_reader.read(), trace, data_json)
def get(self, url): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return search = re.search('^([0-9A-Za-z\-]+)/([0-9A-Za-z\-]+)/(json)?', url) project_key_string = search.group(1) action_key_string = search.group(2) is_json = (search.group(3) == 'json') action_key = ndb.Key( Project, int(project_key_string), ) action_detail_key = ndb.Key(Project, int(project_key_string), Action, int(action_key_string)) project = Project.get_by_id(int(project_key_string)) if not UserManager.get_user_has_privilege_for_operation(project): self.redirect('/') return action = Action.get_by_id(int(action_key_string), parent=action_key) if (action == None): self.redirect('/project/%s/' % project_key_string) return template_path = 'templates/project/action-detail.html' if (is_json): template_path = 'templates/_endpoints/chart-data.json' actions = ActionDetail.query( ancestor=action_detail_key).order(-ActionDetail.date) data = { 'action_name': action.name, 'action_type': action.type, 'action_label': action.label, 'action_x_axis': action.x_axis, 'action_y_axis': action.y_axis, 'action_y_axis_max': action.y_axis_max, 'action_upload_url': blobstore.create_upload_url('/action/import'), 'action_key': action_key_string, 'project_key': project_key_string, 'project_secret': project.secret, 'actions': actions, 'can_use_speed_index': all(a.speed_index > -1 for a in actions), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'data_url': '/project/' + url + 'json', 'sections': [{ "name": "Projects", "url": "/project/list" }, { "name": project.name, "url": "/project/%s/" % project_key_string }, { "name": action.name }] } def remap_extended_info(values): remapped_values = {} for v in values: if v.type not in remapped_values: remapped_values[v.type] = [] try: value = { 'name': v.name, 'type': v.type, 'value': float(v.value) } except Exception, e: if value == None: value = 0.0 # print v remapped_values[v.type].append(value) if 'JavaScript' in remapped_values: remapped_values['JavaScript'] = (sorted( remapped_values['JavaScript'], key=lambda r: float(r['value']), reverse=True)) return remapped_values
class TraceUploadHandler(blobstore_handlers.BlobstoreUploadHandler): def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') project_secret = self.request.get('secret') project = Project.query().filter(Project.secret==project_secret).get() if (project == None): self.response.write(template.render({ "message": "No secret provided" })) return self.response.write(template.render({ "message": blobstore.create_upload_url('/action/import') })) def post(self): # Allow all and sundry to post here, we're going to use the secret as # the method of accepting or denying posts. self.response.headers.add_header('Access-Control-Allow-Origin', '*') template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json') data = self.request.get('data') delete_trace_after_import = True json_decode_error = False chunks_indicator = '=\r?\n' # Just see if AppEngine is treating the data like chunked encoding. # If the data contains chunks, or seems to, remove it. if re.search(chunks_indicator, data): data = re.sub(chunks_indicator, '', data) # Try and parse the posted JSON try: data_json = json.loads(data) except Exception, e: self.response.write(template.render({ "message": 'Unable to parse data' })) return # Check that there is a secret if not 'secret' in data_json: self.response.write(template.render({ "message": "No secret provided" })) return if not 'labels' in data_json: data_json['labels'] = '' project_secret = data_json['secret'] if 'delete-trace-after-import' in data_json: delete_trace_after_import = ( data_json['delete-trace-after-import'] == 'true') uploads = self.get_uploads() if (len(uploads) == 0): self.response.write(template.render({ "message": "No upload found." })) return upload = uploads[0] blob_info = blobstore.BlobInfo(upload.key()) trace = Trace( file_key=upload.key(), date=blob_info.creation, filename=blob_info.filename, processed=False, delete_trace_after_import=delete_trace_after_import ) project = Project.query().filter(Project.secret==project_secret).get() if project == None: self.response.write(template.render({ "message": "No project found with secret %s." % project_secret })) return log = Log( parent=project.key, filename=blob_info.filename, date=(datetime.today() - timedelta(0, 1)), status='File scheduled for import.', records_imported=-1 ) log.put() # Save. trace.put() # Schedule the processing of the trace. taskqueue.add(url='/process', params={ 'key': trace.key.integer_id(), 'data': data }) self.response.write(template.render({ "message": "ok" }))
def get (self, url): if UserManager.get_current_user() == None: self.redirect('/user-not-found') return search = re.search('^([0-9A-Za-z\-]+)/([0-9A-Za-z\-]+)/(json)?', url) project_key_string = search.group(1) action_key_string = search.group(2) is_json = (search.group(3) == 'json') action_key = ndb.Key( Project, int(project_key_string), ) action_detail_key = ndb.Key( Project, int(project_key_string), Action, int(action_key_string) ) project = Project.get_by_id(int(project_key_string)) if not UserManager.get_user_has_privilege_for_operation(project): self.redirect('/') return action = Action.get_by_id(int(action_key_string), parent=action_key) if (action == None): self.redirect('/project/%s/' % project_key_string) return template_path = 'templates/project/action-detail.html' if (is_json): template_path = 'templates/_endpoints/chart-data.json' actions = ActionDetail.query(ancestor=action_detail_key).order( -ActionDetail.date) data = { 'action_name': action.name, 'action_type': action.type, 'action_label': action.label, 'action_x_axis': action.x_axis, 'action_y_axis': action.y_axis, 'action_y_axis_max': action.y_axis_max, 'action_upload_url': blobstore.create_upload_url('/action/import'), 'action_key': action_key_string, 'project_key': project_key_string, 'project_secret': project.secret, 'actions': actions, 'can_use_speed_index': all(a.speed_index > -1 for a in actions), 'sign_out_url': UserManager.get_signout_url(), 'gravatar_url': UserManager.get_gravatar_url(), 'user_email': UserManager.get_email(), 'user_is_admin': UserManager.is_admin(), 'data_url': '/project/' + url + 'json', 'sections': [{ "name": "Projects", "url": "/project/list" },{ "name": project.name, "url": "/project/%s/" % project_key_string }, { "name": action.name }] } def remap_extended_info(values): remapped_values = {} for v in values: if v.type not in remapped_values: remapped_values[v.type] = [] try: value = { 'name': v.name, 'type': v.type, 'value': float(v.value) } except Exception, e: if value == None: value = 0.0 # print v remapped_values[v.type].append(value) if 'JavaScript' in remapped_values: remapped_values['JavaScript'] = ( sorted(remapped_values['JavaScript'], key=lambda r: float(r['value']), reverse=True) ) return remapped_values