allura.scripts
ΒΆ
Provides ScriptTask, a base class for implementing a command-line script that can be run as a task.
To use, subclass ScriptTask and implement two methods:
class MyScript(ScriptTask):
@classmethod
def parser(cls):
'''Define and return an argparse.ArgumentParser instance'''
pass
@classmethod
def execute(cls, options):
'''Your main code goes here.'''
pass
Or using the defopt library (must be installed), subclass DefOptScriptTask and implement one method:
class MyScript(DefOptScriptTask):
@classmethod
def execute(cls, *, limit: int = 10, dry_run: bool = False):
'''
Description/usage of this script
:param limit:
Explanation of parametes, if desired
'''
pass
To call as a script:
if __name__ == '__main__':
MyScript.main()
To run as a background task:
# post the task with cmd-line-style args
MyScript.post('-p myproject --dry-run')