Library¶
Api¶
-
class
ffflash.lib.api.FFApi(content)[source]¶ Helper class provide some easy way to access and modify dictionaries. It only provides reading and replacing already existing keys.
Parameters: content – The initial data to work with
Args¶
Clock¶
Files¶
-
ffflash.lib.files.dump_file(location, content, as_yaml=False)[source]¶ Pickle either json or yaml into a file
Parameters: - location – path where to pickle into
- content – data to store
- as_yaml – output as yaml instead of json
-
ffflash.lib.files.load_file(location, fallback=None, as_yaml=False)[source]¶ Unpickle either json or yaml from a file
Parameters: - location – path where to unpickle from
- fallback – data to return in case of unpickle failure
- as_yaml – read as yaml instead of json
Returns: unpickled data from
location
Locations¶
-
ffflash.lib.locations.check_file_extension(location, *extensions)[source]¶ Validate path for a selection of extensions.
Parameters: - location – path to check
- extensions – one or more extensions the
locationshould end with
Return tuple: (basename of
location, extension oflocation) or (None,None) if extension did not match
-
ffflash.lib.locations.check_file_location(location, must_exist=False)[source]¶ Validate path for a file.
Checks for the parent folder to exist, and that
locationitself is not a folder. Optionally, iflocationis an already existing file.Parameters: - location – path to check
- must_exist – check also if
locationreally exists and is a file
Return str: validated path of
locationif all above conditions are met orNone
-
ffflash.lib.locations.get_basedir()[source]¶ Fancy helper to find project’s basedir. Use
locate_file()to reach into the package folder.Returns: full absolute path to ffflash‘s basedir
-
ffflash.lib.locations.locate_file(*parts, must_exist=False)[source]¶ Find files inside :meth:
get_basedir.Parameters: - parts – trail to your file.
e.g.
bla/fasel/blubbwould be'bla', 'fasel', 'blubb' - must_exist – check if located file really exists and is a file
see
ffflash.lib.files.check_file_location()for more
Returns: full absolute path to desired file, or
Noneon error- parts – trail to your file.
e.g.
Remote¶
-
ffflash.lib.remote.fetch_www(url, fallback=None, timeout=5)[source]¶ Contextmanager to retrieve content from the web
Parameters: - url – URL to fetch
- fallback – what to return instead in case of error
- timeout – timeout to pass to
urllib.request
Yield str: fetched result as unicode string, or
fallback
-
ffflash.lib.remote.fetch_www_struct(url, fallback=None, timeout=5, as_yaml=False)[source]¶ Helper to unpickle either json or yaml from fetched files
Parameters: - url – URL to fetch
- fallback – what to return in case of (fetch or unpickle) error
- timeout – timeout to pass down to
fetch_www() - as_yaml – load content as yaml instead of json
Returns: unpickled data from
url
Struct¶
-
ffflash.lib.struct.dump_struct(content, as_yaml=False)[source]¶ Contextmanager to pickle either json or yaml into a string
Parameters: - content – data to pickle
- as_yaml – output as yaml instead of json
Yield str: pickled
content
Text¶
-
ffflash.lib.text.make_pretty(data)[source]¶ Parameters: data – ugly data Return str: pretty data formatted using pprint.pformat, or Noneif data was too ugly