def getValue(self, args): """ Return the value from the args """ inlineArgs = FlagArg.getValue(self, args) if inlineArgs is None: return {} else: inlineArgs = [arg.split('=') for arg in inlineArgs] return {arg[0]:arg[1] for arg in inlineArgs}
class Install: """ Command to install a package """ description = "Install packages" args = [ PackagesArg(help='Packages to install'), FlagArg('-s', '--save', action='store_true', help='Save the installed packages to the Requirements File'), FlagArg('-p', '--pip', action='store', help='The Pip command to use') ] def run(self, *, packages, save, pip): """ Run the command """ pip = PipWrapper(pipCmd=pip) pip.install(packages) if save: versions = pip.versions() reqFile = RequirementsFile("requirements.txt") reqFile.add(packages, versions)
class ImportCmd: """ Command to import a file and create the necessary Words/Symbols """ description = "Import a file to seed the database" args = [Arg('filename', action='store', help="The file to load"), FlagArg('-l', '--listname', action='store', help="Name of the Concept List to create from the given elements")] def run(self, *, filename, listname): """ Create the new log entry """ eggs = LoadEggs(filename) loader = EggsLoader(eggs) loader.load() if listname is not None: ConceptListLoader(listname, eggs, loader.concepts).load()
class Seed: """ Command to seed the database with all available resource files """ description = "Seed the database with all available resource files" args = [ FlagArg('-n', '--no-staleness', action='store_true', help="Flag to NOT seed Staleness Periods as well") ] def run(self, *, no_staleness=False): """ Create the new log entry """ if not no_staleness: self.addStalenessPeriods() importer = ImportCmd() for filename in glob.glob(os.path.join(EGG_DIR, '*.json')): importer.run(filename, listName=self.getListName(filename)) def addStalenessPeriods(self): """ Add the staleness periods """ previousPeriod = None for days in [180, 90, 30, 14, 7]: if previousPeriod is not None: period = StalenessPeriod(days=days, next=previousPeriod) else: period = StalenessPeriod(days=days) previousPeriod = period server.db.session.add(period) period = StalenessPeriod(days=3, next=previousPeriod, first=True) server.db.session.add(period) server.db.session.commit() def getListName(self, filename): """ Return the list name for the given file """ fullPath = os.path.abspath(filename) basename = os.path.basename(fullPath) filenameWithoutExtension = os.path.splitext(basename)[0] pieces = filenameWithoutExtension.split("_") capitalizedPieces = [piece.capitalize() for piece in pieces] return " ".join(capitalizedPieces)
def __init__(self): """ Initialize the Arg """ FlagArg.__init__(self, '-c', '--config', action="store", help="Config file to use for conversion")
def getValue(self, args): """ Return the value from the args """ filename = FlagArg.getValue(self, args) return ConversionConfig(filename)
def __init__(self, *, help): """ Initialize the Arg """ FlagArg.__init__(self, "-w", "--workspace", action="store", help=help)
def getValue(self, args): """ Return the value from the args """ workspaceName = FlagArg.getValue(self, args) return GlobalConfig.connection.workspaces.withName(workspaceName).first
def __init__(self): """ Initialize the Arg """ FlagArg.__init__(self, '-a', '--args', action="store", nargs='+', help="Specify the additional args: arg=value")
def __init__(self, *, help): """ Initialize the Arg """ FlagArg.__init__(self, "-p", "--project", action="store", help=help)
def getValue(self, args): """ Return the value from the args """ projectName = FlagArg.getValue(self, args) return GlobalConfig.connection.projects.withName(projectName).first