Exemple #1
0
    def _read_folder(self, path, recursive=0, extensions=None):
        if len(path) == 0 or path[-1] != '/': path = path + '/'
        logger.info(" read folder:" + path)
        name = pathlib.Path(path).name
        #files = self._client.list(path)
        files = self._get_files(path)

        alldirs = []
        if recursive != 0 and path != '/':
            parent = str(pathlib.Path(path).parent)
            #print("PATH:",path,"PARENT:",parent)
            alldirs += [Folder('[/..] ' + parent, parent, 0)]

        if len(files) == 0:
            return alldirs

        contents = []
        folders = []
        for f in files:
            if f[0] == '.': continue
            if f[-1] == '/':
                #Include subfolders?
                if recursive > 0:
                    #print(path + f)
                    alldirs += self._read_folder(path + f,
                                                 recursive - 1,
                                                 extensions=extensions)
                elif recursive < 0:
                    #Add the folders without counting their images, unknown image count
                    alldirs += [Folder(f[0:-1], path + f, -1)]
                else:
                    #Just add folders to list if not going into them
                    folders += [f]
            else:
                ext = pathlib.Path(f).suffix.lower()
                if extensions is None or ext in extensions:
                    contents += [f]

        #Skip current if no images or subfolders
        if len(contents) or len(folders):
            #Remove trailing slash for name
            #alldirs += [Folder(name[0:-1], path, len(contents))]
            alldirs += [Folder(name, path, len(contents))]
        logger.info(" read folder entries: " + str(len(alldirs)))
        return alldirs
 def _build_category(self, category):
     name = category['name']
     images = category['nb_images']
     url = category['url']
     subcategories = self._flatten_list([self._build_category(subcat) for subcat in category['sub_categories']]) if category['nb_categories'] > 0 else []
     for subcategory in subcategories:
         subcategory.name = name + ' > ' + subcategory.name
     folder = [Folder(name, url, images)] if images > 0 else []
     return folder + subcategories
Exemple #3
0
 def parse_payload_into_folder(self, original_url, payload):
     result = payload['result']['categories'][0]
     return Folder(result['name'], result['url'], result['nb_images'])
Exemple #4
0
 def parse_payload_into_folder(self, original_url, payload):
     name = original_url.split('/')[-1].title()
     return Folder(name, original_url, len(payload))