Correct non fonctionnal file pattern search

This commit is contained in:
Yorick Barbanneau 2015-12-09 12:08:19 +01:00
parent 40b5b80cef
commit fe51e567ab

View file

@ -5,7 +5,6 @@ Little scrip to export video file for The Internet :D
""" """
import sys import sys
import getopt import getopt
import re
import os import os
import subprocess import subprocess
import logging import logging
@ -41,7 +40,7 @@ params = {
], ],
"webm_acommand": ["-strict", "experimental"], "webm_acommand": ["-strict", "experimental"],
"verbose": True, "verbose": True,
"pattern": "", "pattern": "*",
"twopass": False, "twopass": False,
"recursive": False} "recursive": False}
@ -81,7 +80,12 @@ def list_file(directory, pattern, recursive):
pattern (string) : regex used to found files pattern (string) : regex used to found files
recursive (boolean) : should i serach on sub-folder? recursive (boolean) : should i serach on sub-folder?
""" """
logging.info('searching in directory %s', directory) logging.info(
'searching in directory %s with pattern %s recursive : %s',
directory,
pattern,
recursive
)
files_list = [] files_list = []
try: try:
dirs = os.listdir(directory) dirs = os.listdir(directory)
@ -91,7 +95,7 @@ def list_file(directory, pattern, recursive):
for i in dirs: for i in dirs:
logging.debug(' working on file / dir %s', i) logging.debug(' working on file / dir %s', i)
if os.path.isdir(directory + "/" + i) and recursive: if os.path.isdir(os.path.join(directory, i)) and recursive:
logging.info('directory found : %s', i) logging.info('directory found : %s', i)
files_list.extend(list_file( files_list.extend(list_file(
os.path.join(directory, i), os.path.join(directory, i),
@ -99,7 +103,7 @@ def list_file(directory, pattern, recursive):
recursive recursive
)) ))
else: else:
if re.search(pattern, i) is not None: if i.endswith("." + pattern):
logging.info('file found : %s', i) logging.info('file found : %s', i)
files_list.append(directory + "/" + i) files_list.append(directory + "/" + i)
return files_list return files_list
@ -148,7 +152,7 @@ def process_arg(sysarg):
if opt in ("-i", "--input"): if opt in ("-i", "--input"):
params["file_input"] = arg params["file_input"] = arg
if opt in ("-p", "--pattern"): if opt in ("-p", "--pattern"):
params["pattern"] = "^\\w*."+arg+"$" params["pattern"] = arg
if opt in ("-a", "--abitrate"): if opt in ("-a", "--abitrate"):
params["abitrate"] = arg params["abitrate"] = arg
if opt in ("-v", "--vbitrate"): if opt in ("-v", "--vbitrate"):