def post(self, file_name):
			print self.request.body

			self.application.syncAnnex(file_name, with_metadata=self.request.body)
			res = Result()
			res.result = 200
			self.finish(res.emit())
Example #2
0
        def post(self, route):
            print "GETTING A ROUTE %s" % route
            res = Result()

            if route is not None:
                handler_status = self.application.do_get_status(self)
                route = [r_ for r_ in route.split("/") if r_ != '']

                if route[
                        0] not in self.application.restricted_routes_by_status[
                            handler_status]:
                    # remove _xsrf param; we no longer need it.
                    query = parse_qs(self.request.body)

                    try:
                        del query['_xsrf']
                    except Exception as e:
                        if DEBUG:
                            print e

                    # put request back together again
                    self.request.body = urlencode(query, doseq=True)
                    res = self.application.routeRequest(res, route[0], self)
                else:
                    if DEBUG:
                        print "YOU CANNOT GO TO THERE.  YOUR STATUS IS %d AND YOU WANT %s" % (
                            handler_status, route[0])

            self.set_status(res.result)
            self.finish(res.emit())
Example #3
0
        def get(self, file):
            if 'restrict' in self.application.restrict_source_files.keys():

                if 'exempt' not in self.application.restrict_source_files.keys() or \
                file not in self.application.restrict_source_files['exempt']:

                    srx = r'^/files/\.data/.*'
                    if not re.match(srx, self.request.uri):
                        if self.application.do_get_status(
                                self
                        ) in self.application.restrict_source_files[
                                'restrict']:
                            res = Result()
                            res.result = 403

                            self.set_status(res.result)
                            self.finish(res.emit())
                            return

            url = "%s%s" % (buildServerURL(), self.request.uri)
            if DEBUG:
                print url

            r = requests.get(url, verify=False)

            self.set_header("Content-Type", r.headers['content-type'])
            self.finish(r.content)
		def get(self, uri):
			if uri == "conf.json":
				self.set_header("Content-Type", '%s; charset="utf-8"' % CONTENT_TYPES['json'])

				conf_vars = deepcopy(self.application.init_vars)
				conf_vars['TASK_CHANNEL_URL'] = buildTaskChannelURL(self.request, 
					with_status=self.application.do_get_status(self))
				
				self.finish(json.dumps(conf_vars))
				return
			
			static_path = os.path.join(BASE_DIR, "web")
			asset = os.path.join(static_path, uri)
			
			if not os.path.exists(asset):
				asset = os.path.join(static_path, "extras", uri)
			
			if not os.path.exists(asset):
				res = Result()
				
				self.set_status(res.result)
				self.finish(res.emit())
				return
			
			try:
				content_type = CONTENT_TYPES[asset.split('.')[-1]]
			except Exception as e:
				content_type = CONTENT_TYPES['html']

			self.set_header("Content-Type", '%s; charset="utf-8"' % content_type)

			with open(asset, 'rb') as a:
				self.finish(a.read())
		def post(self, route):
			print "GETTING A ROUTE %s" % route
			res = Result()
		
			if route is not None:
				handler_status = self.application.do_get_status(self)
				route = [r_ for r_ in route.split("/") if r_ != '']

				if route[0] not in self.application.restricted_routes_by_status[handler_status]:
					# remove _xsrf param; we no longer need it.
					query = parse_qs(self.request.body)

					try:
						del query['_xsrf']
					except Exception as e:
						if DEBUG:
							print e

					# put request back together again
					self.request.body = urlencode(query, doseq=True)
					res = self.application.routeRequest(res, route[0], self)
				else:
					if DEBUG:
						print "YOU CANNOT GO TO THERE.  YOUR STATUS IS %d AND YOU WANT %s" % (
							handler_status, route[0])
						
			self.set_status(res.result)					
			self.finish(res.emit())
		def get(self):
			res = Result()
			res.result = 412
			
			res.data = self.application.passToAnnex(self, uri="tasks/")
			if res.data is None:
				del res.data
			elif res.data: res.result = 200
			
			self.set_status(res.result)
			self.finish(res.emit())
		def get(self):
			res = Result()
			res.result = 412
			
			res.data = self.application.do_tasks(self)
			if res.data is None:
				del res.data
			elif res.data: res.result = 200
			
			self.set_status(res.result)
			self.finish(res.emit())
		def post(self):
			res = Result()
			res.status = 412
			
			res.data = self.application.runTask(self)
			if res.data is None:
				del res.data
			elif res.data:
				res.result = 200
			
			self.set_status(res.result)
			self.finish(res.emit())
		def post(self, auth_type):
			res = Result()
			
			if auth_type == "drive" and self.do_get_status in [3,4]:
				status_check = "get_drive_status"
			elif auth_type == "user":
				status_check = "get_user_status"
			
			if status_check is not None:
				res = self.application.routeRequest(res, status_check, self)
			
			if DEBUG: print res.emit()
			
			self.set_status(res.result)
			self.finish(res.emit())
Example #10
0
        def post(self, auth_type):
            res = Result()

            if auth_type == "drive" and self.do_get_status in [3, 4]:
                status_check = "get_drive_status"
            elif auth_type == "user":
                status_check = "get_user_status"

            if status_check is not None:
                res = self.application.routeRequest(res, status_check, self)

            if DEBUG: print res.emit()

            self.set_status(res.result)
            self.finish(res.emit())
		def routeRequest(self, route):
			res = Result()
		
			if route is not None:
				route = [r_ for r_ in route.split("/") if r_ != '']				
				func_name = "do_%s" % route[0]
				
				if hasattr(self.application, func_name):
					if DEBUG : print "doing %s" % func_name
					func = getattr(self.application, str(func_name))
			
					res.result = 200
					res.data = func(self.request)
				else:
					if DEBUG : print "could not find function %s" % func_name

				try:
					if res.data is None: 
						del res.data
						res.result = 412
				except AttributeError as e: pass
						
			self.set_status(res.result)					
			self.finish(res.emit())
		def get(self, file_path):
			# if file exists in git-annex, return the file
			# else, return 404 (file not found)

			if self.application.fileExistsInAnnex(file_path):
				try:
					mime_type = getFileType(os.path.join(ANNEX_DIR, file_path))
				except Exception as e:
					print e
					mime_type = None
				
				with open(os.path.join(ANNEX_DIR, file_path), 'rb') as file:
					if mime_type is not None:
						self.set_header("Content-Type", "%s; charset=\"binary\"" % mime_type)

					self.finish(file.read())
				return
			
			# TODO: log this: we want to know who/why is requesting non-entities
			else:
				self.set_status(404)

			res = Result()
			self.finish(res.emit())
Example #13
0
        def get(self, uri):
            if uri == "conf.json":
                self.set_header("Content-Type",
                                '%s; charset="utf-8"' % CONTENT_TYPES['json'])

                conf_vars = deepcopy(self.application.init_vars)
                conf_vars['TASK_CHANNEL_URL'] = buildTaskChannelURL(
                    self.request,
                    with_status=self.application.do_get_status(self))

                self.finish(json.dumps(conf_vars))
                return

            static_path = os.path.join(BASE_DIR, "web")
            asset = os.path.join(static_path, uri)

            if not os.path.exists(asset):
                asset = os.path.join(static_path, "extras", uri)

            if not os.path.exists(asset):
                res = Result()

                self.set_status(res.result)
                self.finish(res.emit())
                return

            try:
                content_type = CONTENT_TYPES[asset.split('.')[-1]]
            except Exception as e:
                content_type = CONTENT_TYPES['html']

            self.set_header("Content-Type",
                            '%s; charset="utf-8"' % content_type)

            with open(asset, 'rb') as a:
                self.finish(a.read())
		def get(self, file):
			if 'restrict' in self.application.restrict_source_files.keys():

				if 'exempt' not in self.application.restrict_source_files.keys() or \
				file not in self.application.restrict_source_files['exempt']:

					srx = r'^/files/\.data/.*'
					if not re.match(srx, self.request.uri):
						if self.application.do_get_status(self) in self.application.restrict_source_files['restrict']:
							res = Result()
							res.result = 403

							self.set_status(res.result)
							self.finish(res.emit())
							return

			url = "%s%s" % (buildServerURL(), self.request.uri)
			if DEBUG:
				print url
			
			r = requests.get(url, verify=False)

			self.set_header("Content-Type", r.headers['content-type'])
			self.finish(r.content)
Example #15
0
        def get(self):
            res = Result()
            res.result = 412

            res.data = self.application.passToAnnex(self, uri="tasks/")
            if res.data is None:
                del res.data
            elif res.data:
                res.result = 200

            self.set_status(res.result)
            self.finish(res.emit())
Example #16
0
        def post(self):
            res = Result()
            res.result = 412

            query = parseRequestEntity(self.request.body)
            if query is None or len(
                    query.keys()) != 1 or '_id' not in query.keys():
                self.set_status(res.result)
                self.finish(res.emit())
                return

            r = requests.post("%stask/" % buildServerURL(),
                              data={'_id': query['_id']},
                              verify=False)

            try:
                res.data = json.loads(r.content)['data']
                res.result = 200
            except Exception as e:
                if DEBUG: print e

            self.set_status(res.result)
            self.finish(res.emit())
		def post(self):
			res = Result()
			res.result = 412
			
			query = parseRequestEntity(self.request.body)				
			if query is None or len(query.keys()) != 1 or '_id' not in query.keys(): 
				self.set_status(res.result)
				self.finish(res.emit())
				return
							
			r = requests.post("%stask/" % buildServerURL(), 
				data={ '_id' : query['_id'] }, verify=False)
			
			try:
				res.data = json.loads(r.content)['data']
				res.result = 200
			except Exception as e:
				if DEBUG: print e
			
			self.set_status(res.result)
			self.finish(res.emit())
		def get(self, file_name): 
			self.application.syncAnnex(file_name)
			res = Result()
			res.result = 200
			self.finish(res.emit())
		def get(self, route):
			handler_status = self.application.do_get_status(self)
			static_path = os.path.join(BASE_DIR, "web")
			module = "main"
			header = None
			footer = None

			if hasattr(self.application, "WEB_TITLE"): 
				web_title = self.application.WEB_TITLE				
			else:
				web_title = WEB_TITLE
			
			if route is None:
				if hasattr(self.application, "INDEX_HEADER"):
					header = self.application.INDEX_HEADER
				if hasattr(self.application, "INDEX_FOOTER"):
					footer = self.application.INDEX_FOOTER
				
				idx = Template(filename=os.path.join(static_path, "index.html"))
					
			else:
				route = [r for r in route.split("/") if r != '']
				module = route[0]

				if module in self.application.restricted_routes_by_status[handler_status]:
					if DEBUG:
						print "YOU CANNOT GO TO THERE.  YOUR STATUS IS %d AND YOU WANT %s" % (
							handler_status, module)

					res = Result()
					
					self.set_status(res.result)
					self.finish(res.emit())
					return

				if hasattr(self.application, "MODULE_HEADER"):
					header = self.application.MODULE_HEADER
				if hasattr(self.application, "MODULE_FOOTER"):
					footer = self.application.MODULE_FOOTER
			
				idx = Template(filename=os.path.join(static_path, "module.html"))
				web_title = "%s : %s" % (web_title, module)
				
			layout = os.path.join(static_path, "layout", "%s.html" % module)
			
			if DEBUG : print (module, layout)
				
			if not os.path.exists(layout):
				# try the externals...
				layout = os.path.join(static_path, "extras", "layout", "%s.html" % module)
				if DEBUG: 
					print "could not find layout at web root.  trying externals:"
					print layout
				
			if not os.path.exists(layout):
				res = Result()
				
				self.set_status(res.result)
				self.finish(res.emit())
				return

			content = Template(filename=layout).render()

			if header is not None: header = Template(filename=header).render()
			else: header = ""
			
			if footer is not None: footer = Template(filename=footer).render()
			else: footer = ""
			
			self.finish(idx.render(web_title=web_title, 
				on_loader=self.getOnLoad(module, handler_status),
				body_classes = self.get_body_classes(),
				content=content, header=header, footer=footer,
				x_token=self.xsrf_form_html()))
Example #20
0
        def get(self, route):
            handler_status = self.application.do_get_status(self)
            static_path = os.path.join(BASE_DIR, "web")
            module = "main"
            header = None
            footer = None

            if hasattr(self.application, "WEB_TITLE"):
                web_title = self.application.WEB_TITLE
            else:
                web_title = WEB_TITLE

            if route is None:
                if hasattr(self.application, "INDEX_HEADER"):
                    header = self.application.INDEX_HEADER
                if hasattr(self.application, "INDEX_FOOTER"):
                    footer = self.application.INDEX_FOOTER

                idx = Template(
                    filename=os.path.join(static_path, "index.html"))

            else:
                route = [r for r in route.split("/") if r != '']
                module = route[0]

                if module in self.application.restricted_routes_by_status[
                        handler_status]:
                    if DEBUG:
                        print "YOU CANNOT GO TO THERE.  YOUR STATUS IS %d AND YOU WANT %s" % (
                            handler_status, module)

                    res = Result()

                    self.set_status(res.result)
                    self.finish(res.emit())
                    return

                if hasattr(self.application, "MODULE_HEADER"):
                    header = self.application.MODULE_HEADER
                if hasattr(self.application, "MODULE_FOOTER"):
                    footer = self.application.MODULE_FOOTER

                idx = Template(
                    filename=os.path.join(static_path, "module.html"))
                web_title = "%s : %s" % (web_title, module)

            layout = os.path.join(static_path, "layout", "%s.html" % module)

            if DEBUG: print(module, layout)

            if not os.path.exists(layout):
                # try the externals...
                layout = os.path.join(static_path, "extras", "layout",
                                      "%s.html" % module)
                if DEBUG:
                    print "could not find layout at web root.  trying externals:"
                    print layout

            if not os.path.exists(layout):
                res = Result()

                self.set_status(res.result)
                self.finish(res.emit())
                return

            content = Template(filename=layout).render()

            if header is not None: header = Template(filename=header).render()
            else: header = ""

            if footer is not None: footer = Template(filename=footer).render()
            else: footer = ""

            self.finish(
                idx.render(web_title=web_title,
                           on_loader=self.getOnLoad(module, handler_status),
                           body_classes=self.get_body_classes(),
                           content=content,
                           header=header,
                           footer=footer,
                           x_token=self.xsrf_form_html()))