Skip to content

florianeinfalt/fptokens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fptokens

https://readthedocs.org/projects/fptokens/badge/?version=latest https://travis-ci.org/florianeinfalt/fptokens.svg?branch=master

A library for tokenisable filenames

Full Documentation

Installation

To install fptokens, type:

$ pip install fptokens

Getting Started

To get started with fptokens, type:

import fptokens as fpt

To create a file name, type:

filename = fpt.Filename(root='/Users/demo/Desktop',
                        folders=['assets', '$colors$'],
                        base=['asset', '$colors$', '1200px'])

This created a file name with default settings, _ as the separator, jpg as the extension and $ as the escape character for the tokens.

To parse and convert the tokens of the file name to actual tokens, type:

filename.parse()

To get the results of the parsing, type:

print filename.tokens
# [<Token: $color$>]

The list of tokens could now be used to create permutations of the tokenised file name for example for batch output of image assets.

To create a generator of all permutations, define a set of data for each of the tokens with the token name as the argument name:

for permutation in filename.resolve(colors=['white', 'black', 'red', 'blue']):
    # do something with the permutation
    print permutation.abspath
# /Users/demo/Desktop/assets/white/asset_white_1200px.jpg
# /Users/demo/Desktop/assets/black/asset_black_1200px.jpg
# /Users/demo/Desktop/assets/red/asset_red_1200px.jpg
# /Users/demo/Desktop/assets/blue/asset_blue_1200px.jpg

Once tokens have been replaced with real-world data to create permutations, the relevant folders can be created by typing:

permutation.make()