コード例 #1
0
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)
コード例 #2
0
ファイル: import_cmd.py プロジェクト: cloew/VocabTester
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()
コード例 #3
0
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)