def get_path_tree(path): """ Get all of the sub directories of path. """ path = core.normalize_path(path) tree = [] for path, dirs, files in os.walk(path): tree.append(path) return tree
def get_all_parents(path): """ Create a list with all of the parent directories of the file or path. For example ``/Users/penny/Documents`` would be returned as ``['/Users/penny/Documents', '/Users/penny', '/Users/']`` """ path = core.normalize_path(path) parent = os.path.dirname(path) last_parent = None parents = [] while parent != last_parent: parents.append(parent) last_parent = parent parent = os.path.dirname(parent) #print('path:{0}, parents:{1}'.format(path, parents)) return parents
def split_path(path_in): """ Splits a path into a list of its folders. For example ``/Users/penny/Documents`` would be returned as ``['Users', 'penny', 'Documents']`` """ path = core.normalize_path(path_in) drive, path = os.path.splitdrive(path) folders = [] while True: path, folder = os.path.split(path) if folder != '': folders.append(folder) else: if path != '': folders.append(path) break folders.reverse() return folders
def __init__(self): """ Initialize the web application and load saved settings. """ if tornado.options.options.root_path is not None: root_path = core.normalize_path(tornado.options.options.root_path) else: root_path = tornado.options.options.root_path self.toyz_settings = core.ToyzSettings(root_path) # Check that the database is up to date with the current version of Toyz core.check_version(self.toyz_settings.db) # If the user has specified a port, use it if tornado.options.options.port is not None: self.toyz_settings.web.port = tornado.options.options.port # If security is enabled, use the secure versions of the handlers if self.toyz_settings.security.user_login: main_handler = AuthMainHandler static_handler = AuthStaticFileHandler toyz_static_handler = AuthToyzStaticFileHandler toyz_template_handler = AuthToyzTemplateHandler workspace_handler = AuthToyzWorkspaceHandler third_party_handler = AuthToyz3rdPartyHandler benchmark_handler = AuthToyzBenchmarkHandler else: main_handler = MainHandler static_handler = tornado.web.StaticFileHandler toyz_static_handler = ToyzStaticFileHandler toyz_template_handler = ToyzTemplateHandler workspace_handler = ToyzWorkspaceHandler third_party_handler = Toyz3rdPartyHandler benchmark_handler = ToyzBenchmarkHandler self.user_sessions = {} if platform.system() == 'Windows': file_path = os.path.splitdrive(core.ROOT_DIR) else: file_path = '/' handlers = [(r"/", main_handler, { 'template_name': 'home.html', 'template_path': os.path.join(core.ROOT_DIR, 'web', 'templates') }), (r"/auth/login/", AuthLoginHandler), (r"/auth/logout/", AuthLogoutHandler), (r"/static/(.*)", static_handler, { 'path': core.ROOT_DIR }), (r"/workspace/(.*)", workspace_handler), (r"/file/(.*)", static_handler, { 'path': file_path }), (r"/toyz/static/(.*)", toyz_static_handler, { 'path': '/' }), (r"/toyz/templates/(.*)", toyz_template_handler), (r"/third_party/(.*)", third_party_handler, { 'path': core.ROOT_DIR }), (r"/session/(.*)", WebSocketHandler), (r"/benchmark/(.*)", benchmark_handler), (r"/(favicon.ico)", static_handler, { 'path': os.path.join(core.ROOT_DIR, 'web', 'static') })] settings = { 'cookie_secret': self.toyz_settings.web.cookie_secret, 'login_url': '/auth/login/' } tornado.web.Application.__init__(self, handlers, **settings) self.toyz_settings.web.port = self.find_open_port( self.toyz_settings.web.port)
def __init__(self): """ Initialize the web application and load saved settings. """ if tornado.options.options.root_path is not None: root_path = core.normalize_path(tornado.options.options.root_path) else: root_path = tornado.options.options.root_path self.toyz_settings = core.ToyzSettings(root_path) # Check that the database is up to date with the current version of Toyz core.check_version(self.toyz_settings.db) # If the user has specified a port, use it if tornado.options.options.port is not None: self.toyz_settings.web.port = tornado.options.options.port # If security is enabled, use the secure versions of the handlers if self.toyz_settings.security.user_login: main_handler = AuthMainHandler static_handler = AuthStaticFileHandler toyz_static_handler = AuthToyzStaticFileHandler toyz_template_handler = AuthToyzTemplateHandler workspace_handler = AuthToyzWorkspaceHandler third_party_handler = AuthToyz3rdPartyHandler benchmark_handler = AuthToyzBenchmarkHandler else: main_handler = MainHandler static_handler = tornado.web.StaticFileHandler toyz_static_handler = ToyzStaticFileHandler toyz_template_handler = ToyzTemplateHandler workspace_handler = ToyzWorkspaceHandler third_party_handler = Toyz3rdPartyHandler benchmark_handler = ToyzBenchmarkHandler self.user_sessions = {} if platform.system() == 'Windows': file_path = os.path.splitdrive(core.ROOT_DIR) else: file_path = '/' handlers = [ (r"/", main_handler, { 'template_name': 'home.html', 'template_path': os.path.join(core.ROOT_DIR, 'web', 'templates') }), (r"/auth/login/", AuthLoginHandler), (r"/auth/logout/", AuthLogoutHandler), (r"/static/(.*)", static_handler, {'path': core.ROOT_DIR}), (r"/workspace/(.*)", workspace_handler), (r"/file/(.*)", static_handler, {'path': file_path}), (r"/toyz/static/(.*)", toyz_static_handler, {'path': '/'}), (r"/toyz/templates/(.*)", toyz_template_handler), (r"/third_party/(.*)", third_party_handler, {'path':core.ROOT_DIR}), (r"/session/(.*)", WebSocketHandler), (r"/benchmark/(.*)", benchmark_handler), (r"/(favicon.ico)", static_handler, {'path': os.path.join(core.ROOT_DIR,'web','static')}) ] settings={ 'cookie_secret': self.toyz_settings.web.cookie_secret, 'login_url':'/auth/login/' } tornado.web.Application.__init__(self, handlers, **settings) self.toyz_settings.web.port = self.find_open_port(self.toyz_settings.web.port)