def create__single_entry(isFile, path, name): ''' create filesystem return object for file request :param isFile: :param path: :param name: :return: ''' entry = Entry() if not isFile: entry.id = utils.connect_path(utils.connect_path(Config.SITE_BOOK_LIST,path),name) entry.links=[] entry.links.append(Link(entry.id, _get_book_entry_rel(name), name, _get_book_entry_type(name))) else: entry.id = utils.connect_path(utils.connect_path(Config.SITE_BOOK_LIST, path), name) #TODO add Another Links links=fs.getdownloadurl(os.path.dirname(path), name) entry.links=[] if links !=None: for link in links: entry.links.append(Link(link, _get_book_entry_rel(link), name, _get_book_entry_type(link))) entry.content = name entry.title = name entry.updated = utils.getNow() return entry
def getdownloadurl(self, path, name): tmp = connect_path(path, name) files = getFile(self.book_trees, self.getTruePaths(tmp)) return [ connect_path(Config.SITE_BOOK_DONWLOAD, connect_path(path, ee)) for ee in files ]
def listBooks(self, path): """ :return: {entiry ...} """ rslist = [] #not exist! if (path!='/' and not fs.exists(path)): logging.info("dest Path [%s] is Not Exist." % path) return rslist if (fs.isfile(path)): logging.info("dest Path [%s] is a File Not Right." % path) g.book_process = "detail" rslist.append(create__single_entry(True, path, os.path.basename(path))) return rslist bookmap = {} for name in fs.listdir(path): try: name = name.decode("utf-8") except Exception: try: name = name.decode("gbk") except Exception as e: pass file_path = utils.connect_path(path, name) rslist.append(create_entry(fs.isfile(file_path), path, name)) return rslist
def dowloadBook(self, path): """ file :param path: :return: file """ return utils.connect_path(Config.base, path)
def getdownloadurl(self, path, name): tmp = connect_path(path,name) files=getFile(self.book_trees, self.getTruePaths(tmp)) return [connect_path(Config.SITE_BOOK_DONWLOAD,connect_path(path, ee)) for ee in files]
def getdownloadurl(self, path, name): return connect_path(connect_path(Config.SITE_BOOK_DONWLOAD, path), name)
def listdir(self, path): return os.listdir(connect_path(Config.base, path))
def isfile(self, path): return os.path.isfile(connect_path(Config.base, path))
def exists(self, path): return os.path.exists(connect_path(Config.base, path))
def __init__(self): resp=urllib2.urlopen(connect_path(Config.SITE_BOOK_DONWLOAD,'metadata.json')) if resp.getcode() ==200: self.book_trees = json.loads(resp.read())
def __init__(self): resp = urllib2.urlopen( connect_path(Config.SITE_BOOK_DONWLOAD, 'metadata.json')) if resp.getcode() == 200: self.book_trees = json.loads(resp.read())