Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    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
        ]
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def dowloadBook(self, path):
        """
        file
        :param path:
        :return: file
        """

        return utils.connect_path(Config.base, path)
Ejemplo n.º 5
0
    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]
Ejemplo n.º 6
0
 def getdownloadurl(self, path, name):
     return connect_path(connect_path(Config.SITE_BOOK_DONWLOAD, path), name)
Ejemplo n.º 7
0
 def listdir(self, path):
     return os.listdir(connect_path(Config.base, path))
Ejemplo n.º 8
0
 def isfile(self, path):
     return os.path.isfile(connect_path(Config.base, path))
Ejemplo n.º 9
0
 def exists(self, path):
     return os.path.exists(connect_path(Config.base, path))
Ejemplo n.º 10
0
 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())
Ejemplo n.º 11
0
 def getdownloadurl(self, path, name):
     return connect_path(connect_path(Config.SITE_BOOK_DONWLOAD, path),
                         name)
Ejemplo n.º 12
0
 def listdir(self, path):
     return os.listdir(connect_path(Config.base, path))
Ejemplo n.º 13
0
 def isfile(self, path):
     return os.path.isfile(connect_path(Config.base, path))
Ejemplo n.º 14
0
 def exists(self, path):
     return os.path.exists(connect_path(Config.base, path))
Ejemplo n.º 15
0
 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())