def main(args): try: if len(args) != 3: Main.print_with_help("Invalid number of parameters.\n") return 1 dirs = args[:-1] for directory in dirs: if not os.path.isdir(directory): Main.print_with_help("'{}' is not directory.\n".format(directory)) return 1 elif not len(os.listdir(directory)): print("'{}' directory is empty.\n".format(directory)) return 1 search_type = args[-1] # using of strategy pattern if search_type == '-n': searcher = Searcher(SearchByName()) elif search_type == '-c': searcher = Searcher(SearchByContent()) else: Main.print_with_help("Invalid parameter.\n") return 1 searcher.duplicate_search(dirs) searcher.print_results() except Exception as exp: print("Exception: " + str(exp)) return -1
if settings.printusage: common.log('') searchoptions.usage() if settings.printversion: common.log('Version: 0.1') sys.exit(1) try: searcher = Searcher(settings) searcher.search() # print the results if settings.printresults: common.log('') searcher.print_results() if settings.listdirs: dir_list = searcher.get_matching_dirs() if dir_list: common.log('\nDirectories with matches (%d):' % len(dir_list)) for d in dir_list: common.log(d) if settings.listfiles: file_list = searcher.get_matching_files() if file_list: common.log('\nFiles with matches (%d):' % len(file_list)) for f in file_list: common.log(f)
if settings.printversion: common.log('Version: 0.1') sys.exit(1) if settings.debug: common.log('settings: {0!s}'.format(settings)) try: searcher = Searcher(settings) searcher.search() # print the results if settings.printresults: common.log('') searcher.print_results() if settings.listdirs: dir_list = searcher.get_matching_dirs() if dir_list: common.log('\nDirectories with matches (%d):' % len(dir_list)) for d in dir_list: common.log(d) if settings.listfiles: file_list = searcher.get_matching_files() if file_list: common.log('\nFiles with matches (%d):' % len(file_list)) for f in file_list: common.log(f)