Skip to content

Instantly share code, notes, and snippets.

@malleor
Last active December 11, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malleor/4536587 to your computer and use it in GitHub Desktop.
Save malleor/4536587 to your computer and use it in GitHub Desktop.
Script execution concept Opt. 1: Batch files

Concept

  • The algorithm is a script file, exposed to the framework as an importable module.
  • The manifest and input/output params are stored globally.
  • The algorithm is identified as module_name.

Pros

  • With default values for the MANIFEST and DEF_IN_PARAMS, the script is extremely easy to write - see minimal.py.

Cons

  • No visible encapsulation of the execution context - the use of global variables.
  • The need to maintain DEF_IN_PARAMS-IN_PARAMS consistency is a potential source of errors.
from glob import glob
from os import cwd
from os.path import join, split, splitext
from frames import execute
MANIFEST = { # Declare the algorithm info.
'doc': 'Loads all clouds of given format from the CWD.',
'author': 'John Doe',
'version': '0.6',
'multithreaded': False
}
DEF_IN_PARAMS['cloud_extension'] = 'copsxml' # Declare default input params.
if __name__ == '__main__': # Run the script if it's not imported but executed.
cloud_extension = IN_PARAMS['cloud_extension'] # Fetch input params.
cloud_ids = []
for path in glob(join(cwd(), '*.'+cloud_extension)):
name = split(splitext(path)[0])[-1]
cloud_id = execute('import_cloud', path, name)
cloud_ids.append(cloud_id)
OUT_PARAMS['cloud_ids'] = cloud_ids # Form results
print 'Hello, framework.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment