示例#1
0
def init():
    indexDir = constants.getIndexPath()
    indexFilePath = os.path.join(indexDir, constants.getDirIndexName())

    if not os.path.isfile(indexFilePath):
        createClassesFile()
        index()

    classes = constants.getClasses()
    
    # if not classes:
    #     error.noClasses()
    #     return

    
    for c in classes:
        if not os.path.isfile(os.path.join(indexDir, c)):
            index()

    print(":indexed")

    folders = utils.initFoldersList(indexFilePath)
    files = utils.initFilesList(classes, indexDir)
    
    return folders, files
示例#2
0
def index():
    if not os.path.isfile(os.path.join(constants.getIndexPath(), 'classes')):
        setup()

    dataDir = constants.getIndexPath()

    dirIndexName = constants.getDirIndexName()
    fileIndexName = constants.getFileIndexName()

    dirIndexNameTemp = dirIndexName + "_temp"
    fileIndexNameTemp = fileIndexName + "_temp"

    dirIndexFilePath = os.path.join(dataDir, dirIndexNameTemp)
    fileIndexFilePath = os.path.join(dataDir, fileIndexNameTemp)

    folders = []
    files = []

    rootDirs = constants.getRoots()

    for root in rootDirs:
        for dirName, subdirList, fileList in os.walk(root):

            # do not proceed if it's a hidden directory
            if constants.hidden(dirName):
                continue

            dirName = dirName.encode('ascii', "ignore")
            dirName = dirName.decode('ascii', "ignore")
            dirName = str(dirName)
            folders.append(dirName)

            # for f in fileList:
            #     f = f.encode('ascii',"ignore")
            #     f = f.decode('ascii',"ignore")
            #     f = str(f)
            #     if 'linux' in plt:
            #         f = dirName + "/" + f
            #     else:
            #         f = dirName + "\\" + f
            #     files.append(f)

            # for dir in subdirList[:]:
            #     if constants.hidden(dir):
            #         subdirList.remove(dir)

    folders.sort(key=lambda s: len(s))
    # files.sort(key = lambda s: len(s))

    file = open(dirIndexFilePath, 'w')
    for f in folders:
        file.write("%s\n" % f)
    file.close()

    # file = open(fileIndexFilePath, 'w')
    # for f in files:
    #     file.write(f + '\n')
    # file.close()

    utils.deleteAndRename(dataDir, dirIndexName, dirIndexNameTemp)
示例#3
0
def updateFolders():
    indexDir = constants.getIndexPath()
    indexFilePath = os.path.join(indexDir, constants.getDirIndexName())
    folders = utils.initFoldersList(indexFilePath)
    return folders