Esempio n. 1
0
def remote_select_from_walker(tfile, types='all'):
    from workers import concurrent_scrapper
    from Drive import Private as DrivePrivate
    ext = []
    if types != 'all':
        items = types.split(' ')
        for x in items:
            ext.append(str(x).lower())
    folder, TeamDrive = DrivePrivate.folder_walker()
    if TeamDrive == "" or TeamDrive == False:
        TeamDrive = None
    if folder == False:
        return False
    filt = remote_interface_filter()
    order = pick_order()
    if order == False:
        return False
    print(f"- Checking {folder}")
    print("  * Parsing files from Google Drive. Please Wait...")
    db = {}
    db[folder] = {'path': folder, 'TD_name': TeamDrive}
    files = concurrent_scrapper(filter=filt,
                                order=order,
                                remotelib='all',
                                db=db)
    if files == False:
        return False
    print("  * Entering File Picker")
    title = 'Select content to install or transfer: \n + Press space or right to select content \n + Press Enter to confirm selection \n + Press E to exit selection'
    filenames = []
    for f in files:
        if types == 'all':
            filenames.append(f[0])
        else:
            for x in ext:
                if (str(f[0]).lower()).endswith(x):
                    filenames.append(f[0])
                    break
    if filenames == []:
        print("  * Request didn't retrieve any files")
        return False
    options = filenames
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    with open(tfile, 'a') as textfile:
        for f in selected:
            textfile.write((files[f[1]])[2] + '/' + (files[f[1]])[0] + '|' +
                           str(TeamDrive) + '\n')
def Interface():
    clear_Screen()
    About()
    response = False
    print('\n********************************************************')
    print('DOWNLOAD SYSTEM')
    print('********************************************************')
    while True:
        print('Input "1" to select folder and file via file-picker')
        if os.path.exists(remote_lib_file):
            print('Input "2" to select from libraries')
        print('')
        print('Input "0" to go back to the MAIN PROGRAM')
        print('')
        print('--- Or INPUT GDRIVE Route OR PUBLIC_LINK ---')
        print('')
        ck = input('Input your answer: ')
        if ck == "0":
            break
        elif ck == "1":
            while True:
                folder, TD = Private.folder_walker()
                if folder == False:
                    return False
                print(folder)
                response = interface_file(folder, TD)
                if response == False:
                    return False
        elif ck == "2" and os.path.exists(remote_lib_file):
            while True:
                paths, TDs = pick_libraries()
                if paths == False:
                    return False
                response = interface_file(paths, TDs)
                if response == False:
                    return False
        elif ck == "0":
            break
        elif ck.startswith('http'):
            url = ck
            response = interface_menu(url, None, True)
        elif ck.endswith('/') or ck.endswith('\\'):
            response = interface_file(ck, "pick")
        elif (ck[:-1]).endswith('.xc') or (ck[:-1]).endswith('.ns'):
            TD = Private.TD_picker(ck)
            response = interface_menu(ck, TD, True)
        if response == False:
            break