Пример #1
0
def format_all(format_string, env):
    """ Format the input string using each possible combination of lists
        in the provided environment. Returns a list of formated strings.
    """

    prepared_env = parse_pattern(format_string, env, lambda x, y: [FormatWrapper(x, z) for z in y])
    # Generate each possible combination, format the string with it and yield
    # the resulting string:
    for field_values in product(*prepared_env.itervalues()):
        format_env = dict(izip(prepared_env.iterkeys(), field_values))
        yield format_string.format(**format_env)
Пример #2
0
 def run(self, args, config):
     mdb = self.get_metadata_db(args.tree)
     mds = MovieDatasource(config.subsections('datasource'), args.tree, self.profile.object_class)
     listing = self._config(args, config)
     def _sorter((movie_hash, movie)):
         return tuple(movie.get(x) for x in listing['order'])
     movies = sorted(mdb.itermovies(), key=_sorter)
     # Get the current used listing:
     for movie_hash, movie in movies:
         movie = mds.attach(movie_hash, movie)
         prepared_env = parse_pattern(listing['pattern'], movie, ListingFormatWrapper)
         printer.p(u'<inv><b> {hash} </b></inv> ' + listing['pattern'], hash=movie_hash, **prepared_env)
Пример #3
0
    def run(self, args, config):
        mdb = self.get_metadata_db(args.tree)
        mds = MovieDatasource(config.subsections('datasource'), args.tree, self.profile.object_class)
        webexport = self._config(args, config)
        columns = [(x.args, x) for x in webexport['columns']]
        movies = []

        for movie_hash, movie in sorted(mdb.itermovies(), key=lambda x: x[1].get('title')):
            filename = os.path.join(args.pool_path, movie_hash)
            movie_columns = []
            movie = mds.attach(movie_hash, movie)
            for column in webexport['columns']:
                prepared_env = parse_pattern(column.get('pattern'), movie, WebExportFormatWrapper)
                movie_columns.append(column.get('pattern').format(**prepared_env))
            movies.append((filename, movie, movie_columns))

        template = jinja2.Template(LISTING_TEMPLATE)
        with open(args.destination, 'w') as fdest:
            fdest.write(template.render(columns=columns,
                                        movies=movies,
                                        title=webexport['page_title'],
                                        credits=webexport['page_credits']).encode('utf8'))