当前位置: 首页>>代码示例>>Python>>正文


Python Output.options方法代码示例

本文整理汇总了Python中Output.options方法的典型用法代码示例。如果您正苦于以下问题:Python Output.options方法的具体用法?Python Output.options怎么用?Python Output.options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Output的用法示例。


在下文中一共展示了Output.options方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: options

# 需要导入模块: import Output [as 别名]
# 或者: from Output import options [as 别名]
def options(fastSearchDir, optionsList, colors):
    Output.options(optionsList, colors)
    
    # loop until the user wants to go back
    while True:
        # capture the users choice
        string = raw_input(colors.cyan() + 'Enter an option: ' + colors.end()).lower()

        # the user wants to enable or disable a deep search
        if string in ('d', 'deep', 'deep search', 'ds'):
            optionsList[0] = not optionsList[0]
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Deep Search is now %s' % (optionsList[0] and 'on' or 'off') + '...\n' + colors.end()
        # the user wants only files to be displayed in the results
        elif string in ('i', 'file', 'files', 'file only', 'files only', 'only file', 'only files'):
            optionsList[1] = 0
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will now only include files...\n' + colors.end()
        # the user wants only folders to be displayed in the results
        elif string in ('e', 'folder', 'folders', 'folder only', 'folders only', 'only folder', 'only folders'):
            optionsList[1] = 1
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will now only include folders...\n' + colors.end()
        # the user wants both files and folders to be displayed in the results
        elif string in ('o', 'both', 'both file and foler', 'both files and folder', 'both file and folders', 'both files and folders', 'file and folder', \
                        'files and folder', 'file and folders', 'files and folders', 'bff'):
            optionsList[1] = 2
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will now include both files and folders...\n' + colors.end()
        # the user wants to enable or disable the display of hidden files and folders in the results
        elif string in ('h', 'hidden', 'show hidden', 'show hidden file', 'show hidden files', 'show hidden folder', 'show hidden folders', \
                        'hidden file and folder', 'hidden files and folder', 'hidden file and folders', 'hidden files and folders', 'show hidden file and folder', \
                        'show hidden files and folder', 'show hidden file and folders', 'show hidden files and folders', 'hide file', 'hide files', \
                        'hide folder', 'hide folders', 'hide file and folder', 'hide files and folder', 'hide file and folders', 'hide files and folders'):
            optionsList[2] = not optionsList[2]
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will %s show hidden files and folders' % (optionsList[2] and 'now' or 'no longer') + '...\n' + colors.end()
        # the user wants the absolute path to be shown in the search results
        elif string in ('f', 'full path', 'abs', 'absolute', 'abspath', 'abs path', 'absolute path'):
            optionsList[3] = 0
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will now show the full (absolute) path...\n' + colors.end()
        # the user wants the relative path to be shown in the search results
        elif string in ('r', 'rel', 'relative', 'relpath', 'rel path', 'relative path'):
            optionsList[3] = 1
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will now show the relative path...\n' + colors.end()
        # the user doesn't want the path shown in the search results
        elif string in ('n', 'no path'):
            optionsList[3] = 2
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Search results will no longer show a path...\n' + colors.end()
        # the user wants to enable or disable a full search
        elif string in ('u', 'full search', 'partial', 'partial search'):
            optionsList[4] = not optionsList[4]
            FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
            print colors.alert() + '...Full Search is now %s' % (optionsList[4] and 'on' or 'off') + '...\n' + colors.end()
        # the user wants to change the root directory
        elif string in ('dir', 'directory', 'r', 'root', 'rootdir', 'root dir', 'root directory', 'curdir', 'cur dir', 'cur directory', 'current directory'):
            string = raw_input(colors.cyan() + 'Enter the path for the new root director: ' + colors.end())
            # ensure that the user has given a valid new root directory
            if os.path.exists(string):
                optionsList[5] = string
                if not optionsList[6] == None:
                    optionsList[6].close()
                optionsList[6] = None
                FileHandler.writeNewOptionsList(fastSearchDir, optionsList, True)
                print colors.alert() + '...The new root directory is ' + optionsList[5] + '...\n' + colors.end()
            # if the directory isn't local, perhaps it is an ftp location
            elif isValidRemoteConn(string):
                string = string.replace('ftp://', '')
                if not string.startswith('ftp.'):
                    string = 'ftp.' + string
                localDir = None
                if not string.find('/') == -1:
                    address = string[:string.find('/')]
                    localDir = string[string.find('/'):]
                else:
                    address = string
                username = raw_input(colors.cyan() + 'Username: ' + colors.end())
                password = getpass.getpass(colors.cyan() + 'Password: ' + colors.end())
                if isValidLogin(address, username, password):
                    temp = optionsList[5]
                    optionsList[5] = address
                    ftp = ftplib.FTP(address)
                    ftp.login(username, password)
                    if not localDir == None or (not localDir == None and localDir.strip() == ''):
                        try:
                            ftp.cwd(localDir)
                            optionsList[5] += localDir
                        except:
                            optionsList[5] = temp
                            print colors.error() + 'The remote server was valid, but the specified local directory, ' + localDir + ', could not be found.' \
                                  + '\nCheck your spelling, verify that the directory exists, and try again. The root directory has not changed.' + colors.end()
                            print colors.alert() + '...The root directory remains ' + optionsList[5] + '...\n' + colors.end()
                            continue
                    if not optionsList[6] == None:
                        optionsList[6].close()
                    optionsList[6] = ftp
                    print colors.alert() + '...The new root directory is ' + optionsList[5] + '...\n' + colors.end()
#.........这里部分代码省略.........
开发者ID:alexdlaird,项目名称:fastsearch,代码行数:103,代码来源:Options.py


注:本文中的Output.options方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。