예제 #1
0
 def indexing(self, update=False):
     """
     Indexing recipes locally
     """
     if not self.is_indexed() or update:
         self.index[self.id] = {'remote': self.remote, 'version': self.version,
                                'filename': self.filename, 'datetime': str(datetime.now())}
         Storage.json(settings.get('STORAGE_RECIPE_INDEX'), self.index)
예제 #2
0
    def remove(rid):
        """
        Remove locally recipe by id
        """
        location = settings.get('STORAGE_RECIPE_INDEX')
        index = Storage.json(location)

        if len(rid) != 64:
            found = list(filter(lambda idx: idx[:9] == rid, index))
            if found:
                rid = found[0]

        del index[rid]
        Storage.json(location, index)
        logger.log("Removed recipe '%s'" % rid)
예제 #3
0
    def list(all_info=False):
        """
        List of recipes saved in index
        """
        recipes = Storage.json(settings.get('STORAGE_RECIPE_INDEX'))
        meta = _IndexRecipe.calc_length(recipes)
        meta['id'] = 64 if all_info else 9
        extra_space = 8
        list_items = ''

        for key in recipes.keys():
            recipe = recipes[key]
            recipe_id = key[:meta['id']]
            created = recipe['datetime'] if all_info else recipe['datetime'][:19]

            list_items += recipe_id + (' ' * (meta['id'] + extra_space - len(recipe_id)))

            for attr_name in ['remote', 'version', 'filename']:
                list_items += (recipe[attr_name] +
                               (' ' * (meta[attr_name] + extra_space - len(recipe[attr_name]))))

            list_items += created + '\n'

        header = ListRecipes._list_header(meta, extra_space)
        logger.log(header + list_items)
예제 #4
0
 def __init__(self, remote, version, filename):
     self.remote = remote
     self.version = version
     self.filename = filename
     self.id = self._generate_id()
     self.index = Storage.json(settings.get('STORAGE_RECIPE_INDEX'))