예제 #1
0
def gen_sx_autoloader_files_menu():
	print('***********************************************')
	print('SX AUTOLOADER GENERATE FILES FROM HDD OR FOLDER')
	print('***********************************************')
	print('')
	folder=input("Input a drive path: ")
	if not os.path.exists(folder):
		sys.exit("Can't find location")
	title = 'Target for autoloader files: '	
	options = ['HDD','SD']		
	selected = pick(options, title, min_selection_count=1)
	if selected[0]=='HDD':
		type='hdd'
	else:
		type='sd'
	title = 'Push files after generation?: '		
	options = ['YES','NO']			
	selected = pick(options, title, min_selection_count=1)
	if selected[0]=='YES':
		push=True
	else:
		push=False
	title = "Ensure files can't colide after transfer?: "		
	options = ['YES','NO']			
	selected = pick(options, title, min_selection_count=1)		
	if selected[0]=='YES':
		no_colide=True
	else:
		no_colide=False
	gen_sx_autoloader_files(folder,type=type,push=push,no_colide=no_colide)	
예제 #2
0
def push_sx_autoloader_libraries():
	if not is_switch_connected():
		sys.exit("Can't push files. Switch device isn't connected.\nCheck if mtp responder is running!!!")		
	title = "Ensure files can't colide after transfer?: "		
	options = ['YES','NO']				
	selected = pick(options, title, min_selection_count=1)		
	if selected[0]=='YES':
		no_colide=True
	else:
		no_colide=False				
	print('  * Pushing autoloader files in hdd folder')			
	HDD_folder=os.path.join(sx_autoloader_db, 'hdd')
	destiny="1: External SD Card\\sxos\\titles\\00FF0012656180FF\\cach\\hdd"
	process=subprocess.Popen([nscb_mtp,"TransferFolder","-ori",HDD_folder,"-dst",destiny,"-fbf","true"])
	while process.poll()==None:
		if process.poll()!=None:
			process.terminate();		
	print('  * Pushing autoloader files in SD folder')					
	SD_folder=os.path.join(sx_autoloader_db, 'sd')		
	destiny="1: External SD Card\\sxos\\titles\\00FF0012656180FF\\cach\\sd"
	process=subprocess.Popen([nscb_mtp,"TransferFolder","-ori",SD_folder,"-dst",destiny,"-fbf","true"])
	while process.poll()==None:
		if process.poll()!=None:
			process.terminate();
	if no_colide==True:
		cleanup_sx_autoloader_files()	
						
def interface_compressedf_mode():
    from python_pick import pick
    title = 'Compressed files detected. Input download mode'
    options = ['Compressed', 'Uncompressed']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    return response
def interface_xci_mode():
    from python_pick import pick
    title = 'Xci files detected. Input download mode'
    options = ['Untrimmed', 'Trimmed', 'Supertrimmed']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    return response
예제 #5
0
def pick_download_folder():
    title = 'Select download folder: '
    db = libraries(download_lib_file)
    if db == False:
        return False, False
    options = [x for x in db.keys()]
    selected = pick(options, title, min_selection_count=1)
    path = (db[selected[0]])['path']
    return path
def pick_download_folder():
    from python_pick import pick
    title = 'Select download folder: '
    db = libraries(download_lib_file)
    if db == False:
        return False, False
    options = [x for x in db.keys()]
    selected = pick(options, title, min_selection_count=1)
    path = selected[0]
    return path
예제 #7
0
def pick_transfer_folder():
    if not os.path.exists(mtp_internal_lib):
        return "SD"
    title = 'Select transfer folder: '
    db = libraries(mtp_internal_lib)
    if db == False:
        return "SD"
    options = [x for x in db.keys()]
    selected = pick(options, title, min_selection_count=1)
    path = (db[selected[0]])['path']
    return path
예제 #8
0
def TD_picker(path):
    remote = location(route=path)
    names, ids = get_TeamDrives(remote.token_name)
    if names:
        title = 'Select Teamdrive (press SPACE\RIGHT to mark\\unmark, ENTER to continue): \n"None" will return the My-Drive section of the account'
        options = names
        selected = pick(options, title, min_selection_count=1)
        TD = selected[0]
        if TD == 'None':
            TD = None
    else:
        TD = None
    return TD
예제 #9
0
def remote_interface_filter_local(filelist):
    title = 'Add a search filter?: '
    options = ['Yes', 'No']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    if response == 'No':
        return filelist
    else:
        clear_Screen()
        About()
        ck = input('INPUT SEARCH FILTER: ')
        filelist = listmanager.filter_vlist(filelist, token=ck, Print=False)
    return filelist
예제 #10
0
def interface_filter(path=None):
	title = 'Add a search filter?: '
	options = ['Yes','No']	
	selected = pick(options, title, min_selection_count=1)
	response=selected[0]
	if response=='No':
		return None
	else:
		clear_Screen()
		About()
		if path != None:
			print("Filepath {}\n".format(str(path)))
		ck=input('INPUT SEARCH FILTER: ')
		return ck
예제 #11
0
def search_with_filter(folder_paths, extlist=['nsp', 'nsz', 'xci', 'xcz']):
    filepaths = []
    title = 'Add a search filter?: '
    options = ['Yes', 'No']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    if response == 'No':
        for fo in folder_paths:
            rlist = listmanager.folder_to_list(fo, extlist)
            filepaths = [*filepaths, *rlist]
        return filepaths
    else:
        clear_Screen()
        About()
        ck = input('INPUT SEARCH FILTER: ')
        for fo in folder_paths:
            rlist = listmanager.folder_to_list(fo, extlist, ck)
            filepaths = [*filepaths, *rlist]
        return filepaths
예제 #12
0
def pick_libraries():
	title = 'Select libraries to search: '
	db=libraries(remote_lib_file)
	if db==False:
		return False,False
	options = [x for x in db.keys()]
	selected = pick(options, title,multi_select=True,min_selection_count=1)	
	# print(selected)
	paths=list();TDs=list()
	for entry in selected:
		paths.append((db[entry[0]])['path'])
		try:
			TDs.append((db[entry[0]])['TD_name'])
		except:
			TDs.append(None)
	# for p in range(len(paths)):
		# print(paths[p])
		# print(TDs[p])		
	return paths,TDs	
예제 #13
0
def token_picker():
    files = folder_to_list(credentials_dir, "all")
    # print(files)
    tokens = list()
    names = list()
    for file in files:
        bname = os.path.basename(os.path.abspath(file))
        test = bname.split(".")
        if len(test) == 1 and file not in tokens:
            tokens.append(file)
            names.append(str(os.path.basename(os.path.abspath(file))))
    if len(names) > 1:
        title = 'Pick an account (press SPACE\RIGHT to mark\\unmark, ENTER to continue): '
        options = names
        selected = pick(options, title, min_selection_count=1)
        tok = names[selected[1]]
    elif len(names) == 1:
        tok = names[0]
    else:
        tok = False
    return tok
예제 #14
0
def search_folder(path,
                  TD=None,
                  ext=None,
                  filter=None,
                  order=None,
                  mime='files',
                  Pick=True,
                  Print=True,
                  pickmode='multi'):
    file_list = list()
    userfilter = filter
    isroot = False
    TDlist = False
    file_listv2 = list()
    if isinstance(path, list):
        paths = path
    else:
        paths = path.split('.+')
    if isinstance(TD, list):
        TDlist = TD
    index = 0
    for path in paths:
        # print(path)
        try:
            if userfilter == None or filter == "":
                filter = ""
            else:
                filter = " and name contains '{}'".format(userfilter)
            if TDlist != False:
                TD = TDlist[index]
                index += 1
            if TD == "pick":
                TD = TD_picker(path)
            if TD != None:
                remote = location(route=path, TD_Name=TD)
            else:
                remote = location(route=path)
            drive_service = remote.drive_service
            if drive_service == None:
                if remote.token_name == None:
                    auth = auth()
                else:
                    auth = auth(token=token_name)
                drive_service = auth.drive_service
            tk, fl = get_path_parameters(path)
            if not fl and TD == None:
                root = 'root'
                remote.root = root
                remote.ID = root
            elif not fl:
                root = remote.ID
                remote.root = root
                remote.ID = root
            else:
                root = remote.root
            # print(remote.ID)
            if mime == 'files':
                page_token = None
                pagesize = 1000
                while True:
                    if root != 'root':
                        results = drive_service.files().list(
                            q="mimeType!='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields=
                            "nextPageToken, files(id, name, size, createdTime)",
                            includeItemsFromAllDrives=True,
                            supportsAllDrives=True).execute()
                    else:
                        results = drive_service.files().list(
                            q="mimeType!='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields=
                            "nextPageToken, files(id, name, size, createdTime)"
                        ).execute()
                    items = results.get('files', [])
                    try:
                        page_token = results.get('nextPageToken', None)
                    except:
                        pass
                    for file in items:
                        try:
                            file_list.append([
                                file['name'], file['size'], path,
                                file['createdTime']
                            ])
                        except:
                            pass
                    if Print == True:
                        print(f'- {path}: Total Retrieved ' +
                              str(len(file_list)))
                    if page_token == None:
                        break
            elif mime == 'folders':
                page_token = None
                pagesize = 100
                while True:
                    if root != 'root':
                        results = drive_service.files().list(
                            q="mimeType='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields="nextPageToken, files(id, name)",
                            includeItemsFromAllDrives=True,
                            supportsAllDrives=True).execute()
                    else:
                        results = drive_service.files().list(
                            q="mimeType='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields="nextPageToken, files(id, name)").execute()
                    items = results.get('files', [])
                    try:
                        page_token = results.get('nextPageToken', None)
                    except:
                        pass
                    for file in items:
                        try:
                            file_list.append([file['name'], path])
                        except:
                            pass
                    if Print == True:
                        print(f'- {path}: Total Retrieved ' +
                              str(len(file_list)))
                    if page_token == None:
                        break
        except:
            print(f'- {path}: Retrieved 0')
            return False
    if not file_list:
        return False
    file_list.sort(key=lambda x: x[0])
    if Pick == True:
        if pickmode != 'single':
            title = 'Select results (press SPACE\RIGHT to mark\\unmark, ENTER to continue): '
        elif mime == "files":
            title = 'Select result:'
        else:
            title = 'Select result:\n + Press space or right to select content \n + Press E to finish selection'
        oplist = list()
        cleanlist = list()
        if mime == 'folders':
            for item in file_list:
                oplist.append(item[0])
                cleanlist.append(clean_name(item[0]))
        else:
            for item in file_list:
                sz = str(sq_tools.getSize(int(item[1])))
                oplist.append(item[0] + ' | ' + sz)
                cleanlist.append(clean_name(item[0]) + ' | ' + sz)
        options = cleanlist
        if pickmode != 'single':
            selected = pick(options,
                            title,
                            multi_select=True,
                            min_selection_count=0)
        elif mime == "files":
            selected = pick(options, title, min_selection_count=1)
            if selected[0] == False:
                return False
        else:
            picker = Picker(options, title, 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:
                return False
        # print (selected)
        oplist = file_list
        file_list = list()
        if pickmode == 'single':
            if mime == 'folders':
                basepath = oplist[selected[1]][1]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[selected[1]][0]
            else:
                basepath = oplist[selected[1]][2]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[selected[1]][0]
            return pth
        if mime == 'folders':
            for file in selected:
                basepath = oplist[file[1]][1]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[file[1]][0]
                file_list.append(pth)
        else:
            for file in selected:
                basepath = oplist[file[1]][2]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[file[1]][0]
                file_list.append(pth)
        if not file_list:
            return False
        if Print == True:
            print("\n- User selected the following results: ")
            for file in file_list:
                print(file)
        else:
            print("- User selected {} files".format(str(len(file_list))))
        if TDlist != False and file_list:
            file_listv2.append([file_list, TD])
    if TDlist != False:
        return file_listv2
    return file_list
예제 #15
0
def get_files_from_walk(tfile=None,
                        extlist=['nsp', 'nsz', 'xci', 'xcz'],
                        filter=False,
                        recursive=False,
                        doPrint=False):
    if not isinstance(extlist, list):
        if str(extlist).lower() != 'all':
            ext = extlist.split()
            extlist = []
            for x in ext:
                extlist.append(x)
    folder, rec = folder_walker()
    if folder == False:
        return False
    if rec == True:
        recursive = True
    print("Parsing files. Please wait...")
    title = 'Add a search filter?: '
    options = ['Yes', 'No']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    if response == 'No':
        pass
    else:
        clear_Screen()
        About()
        filter = input('INPUT SEARCH FILTER: ')
    if recursive == False:
        files = listmanager.nextfolder_to_list(folder,
                                               extlist=extlist,
                                               filter=filter)
    else:
        files = listmanager.folder_to_list(folder,
                                           extlist=extlist,
                                           filter=filter)
    if not files:
        sys.exit("Query didn't return any files")
    order = pick_order()
    if order == False:
        return False
    filedata = {}
    for file in files:
        try:
            fname = os.path.basename(file)
            fsize = os.path.getsize(file)
            fdate = os.path.getctime(file)
            entry = {
                'filepath': file,
                'filename': fname,
                'size': fsize,
                'date': fdate
            }
            if not fname in filedata:
                filedata[fname] = entry
        except:
            pass
    options = []
    if order == 'name_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
    elif order == 'name_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
        options.reverse()
    elif order == 'size_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
    elif order == 'size_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
        options.reverse()
    elif order == 'date_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
    elif order == 'date_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
        options.reverse()
    title = 'Select content: \n + Press space or right to select entries \n + Press Enter to confirm selection \n + Press E to exit selection \n + Press A to select all entries'
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    def select_all(picker):
        return "ALL", -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    picker.register_custom_handler(ord('a'), select_all)
    picker.register_custom_handler(ord('A'), select_all)
    selected = picker.start()
    if selected[0] == False:
        print("User didn't select any files")
        return False
    newgpaths = []
    if selected[0] == "ALL":
        for game in options:
            newgpaths.append(os.path.join(folder, game))
    else:
        for game in selected:
            newgpaths.append(os.path.join(folder, game[0]))
    if tfile != None:
        with open(tfile, 'w', encoding='utf8') as textfile:
            for i in newgpaths:
                textfile.write((i).strip() + "\n")
    if doPrint != False:
        for i in newgpaths:
            print(i)
    return newgpaths