Esempio n. 1
0
def updateDbs(apps):
    """Used to create .pkl files for any apps or plugins the are declared
    supported but don't have an up-to-date pkl file.
    Takes a list of appnames.
    """
    for app in apps:
        print(config.getDbPath(app))
        if not os.access(config.getDbPath(app), os.F_OK):
            print("No db file available for app %s. Creating it from %s..." % (app, config.getAppPath(app)))
            pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPath(app), config.APP_CONFIG[app]["versionDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
            dt.saveTables(config.getDbPath(app), pathNodes, versionNodes, allversions)
        else:
            print("Found db file for app %s" % app, end=' ')
            #print "(path is ", config.getDbPath(app), ")"
            pathNodes, versionNodes, allversions = dt.loadTables(config.getDbPath(app), False)
            versInDb = len(allversions)
            versOnDisk = len([entry for entry in os.listdir(config.getAppPath(app)) if re.match(config.APP_CONFIG[app]["versionDirectoryRegex"], entry)])

            #versInDb = set(ver.vstring for ver in allversions)
            #versOnDisk = set([entry for entry in os.listdir(config.getAppPath(app)) if re.match(config.APP_CONFIG[app]["versionDirectoryRegex"], entry)])
            #verDifferences = versInDb ^ versOnDisk
            #print "DB: %s\nDisk: %s\nDiffs: %s" % (versInDb, versOnDisk, verDifferences)
            if versInDb != versOnDisk:
                print("but it is out of date (%s versions in db, %s versions on disk). Recreating it from %s... " % (versInDb, versOnDisk, config.getAppPath(app)))
                pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPath(app), config.APP_CONFIG[app]["versionDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
                dt.saveTables(config.getDbPath(app), pathNodes, versionNodes, allversions)
            else:
                print(".")

        if os.access(config.getAppPluginPath(app), os.F_OK):
            for plugin in [p for p in sorted(os.listdir(config.getAppPluginPath(app))) if os.path.isdir(config.getAppPluginPath(app, p))]:
                if not os.access(config.getDbPath(app, plugin), os.F_OK):
                    print("No db file available for %s plugin %s. Creating it from %s..." % (app, plugin, config.getAppPluginPath(app, plugin)))
                    pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPluginPath(app, plugin),  plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], "none", config.APP_CONFIG[app]["fileExcludeRegex"])
                    dt.saveTables(config.getDbPath(app, plugin), pathNodes, versionNodes, allversions)
                else:
                    print("Found db file for %s plugin %s" % (app, plugin), end=' ')
                    pathNodes, versionNodes, allversions = dt.loadTables(config.getDbPath(app, plugin), False)
                    versInDb = len(allversions)
                    versOnDisk = len([entry for entry in os.listdir(config.getAppPluginPath(app, plugin)) if re.match(plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], entry)])
                    if versInDb != versOnDisk:
                        print("but it is out of date (%s versions in db, %s versions on disk). Recreating it from %s... " % (versInDb, versOnDisk, config.getAppPluginPath(app, plugin)))
                        pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPluginPath(app, plugin), plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
                        dt.saveTables(config.getDbPath(app, plugin), pathNodes, versionNodes, allversions)
                    else:
                        print(".")
def updateDbs(apps):
    """Used to create .pkl files for any apps or plugins the are declared 
    supported but don't have an up-to-date pkl file. 
    Takes a list of appnames.
    """
    for app in apps:
        if not os.access(config.getDbPath(app), os.F_OK):
            print "No db file available for app %s. Creating it from %s..." % (app, config.getAppPath(app))
            pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPath(app), config.APP_CONFIG[app]["versionDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
            dt.saveTables(config.getDbPath(app), pathNodes, versionNodes, allversions)
        else:
            print "Found db file for app %s" % app,
            #print "(path is ", config.getDbPath(app), ")"
            pathNodes, versionNodes, allversions = dt.loadTables(config.getDbPath(app), False)
            versInDb = len(allversions)
            versOnDisk = len(filter(lambda entry: re.match(config.APP_CONFIG[app]["versionDirectoryRegex"], entry),os.listdir(config.getAppPath(app))))

            #versInDb = set(ver.vstring for ver in allversions)
            #versOnDisk = set([entry for entry in os.listdir(config.getAppPath(app)) if re.match(config.APP_CONFIG[app]["versionDirectoryRegex"], entry)])
            #verDifferences = versInDb ^ versOnDisk
            #print "DB: %s\nDisk: %s\nDiffs: %s" % (versInDb, versOnDisk, verDifferences)
            if versInDb != versOnDisk:
                print "but it is out of date (%s versions in db, %s versions on disk). Recreating it from %s... " % (versInDb, versOnDisk, config.getAppPath(app))
                pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPath(app), config.APP_CONFIG[app]["versionDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
                dt.saveTables(config.getDbPath(app), pathNodes, versionNodes, allversions)
            else:
                print "."
        
        if os.access(config.getAppPluginPath(app), os.F_OK):
            for plugin in filter(lambda p: os.path.isdir(config.getAppPluginPath(app, p)), sorted(os.listdir(config.getAppPluginPath(app)))):
                if not os.access(config.getDbPath(app, plugin), os.F_OK):
                    print "No db file available for %s plugin %s. Creating it from %s..." % (app, plugin, config.getAppPluginPath(app, plugin))
                    pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPluginPath(app, plugin),  plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], "none", config.APP_CONFIG[app]["fileExcludeRegex"])
                    dt.saveTables(config.getDbPath(app, plugin), pathNodes, versionNodes, allversions)
                else:
                    print "Found db file for %s plugin %s" % (app, plugin),
                    pathNodes, versionNodes, allversions = dt.loadTables(config.getDbPath(app, plugin), False)                    
                    versInDb = len(allversions)
                    versOnDisk = len(filter(lambda entry: re.match(plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], entry),os.listdir(config.getAppPluginPath(app, plugin))))
                    if versInDb != versOnDisk:
                        print "but it is out of date (%s versions in db, %s versions on disk). Recreating it from %s... " % (versInDb, versOnDisk, config.getAppPluginPath(app, plugin))
                        pathNodes, versionNodes, allversions = dt.computeTables(config.getAppPluginPath(app, plugin), plugin+config.APP_CONFIG[app]["pluginsDirectoryRegex"], config.APP_CONFIG[app]["directoryExcludeRegex"], config.APP_CONFIG[app]["fileExcludeRegex"])
                        dt.saveTables(config.getDbPath(app, plugin), pathNodes, versionNodes, allversions)
                    else:
                        print "."