Accept a single file as parameter to parse

This commit is contained in:
Julian Knauer 2017-10-02 14:14:54 +02:00
parent e4d9dfe1ae
commit 3a879b042c
1 changed files with 17 additions and 15 deletions

View File

@ -47,23 +47,25 @@ if __name__ == '__main__':
sys.argv.remove('--' + option)
if len(sys.argv) <= 1 or len(sys.argv) > 2:
raise IndexError
scanpath = sys.argv[-1]
scan_path = sys.argv[-1]
if os.name == 'nt':
if not scanpath[-1] == '\\':
scanpath += '\\'
scanpath = scanpath.replace('\\', '\\\\')
if not scan_path[-1] == '\\' and os.path.isdir(scan_path):
scan_path += '\\'
scan_path = scan_path.replace('\\', '\\')
else:
if not scanpath[-1] == '/':
scanpath += '/'
if not scan_path[-1] == '/' and os.path.isdir(scan_path):
scan_path += '/'
except IndexError:
print('Not enough parameters.\n Usage: {} [--short|--files] <directory>'.format(sys.argv[0]))
print('Not enough parameters.\n Usage: {} [--short|--files] <directory|filename>'.format(sys.argv[0]))
sys.exit(1)
for index, torrentfile in enumerate(glob.glob(scanpath + '*.torrent')):
torrentfile = torrentfile.replace('\\', '\\')
parse_torrent_file(torrentfile)
try:
print('Found {} .torrent files.'.format(index+1))
except NameError:
print('No valid files found.')
sys.exit(1)
if os.path.isdir(scan_path):
for index, torrentfile in enumerate(glob.glob(scan_path + '*.torrent')):
parse_torrent_file(torrentfile)
try:
print('Found {} .torrent files.'.format(index+1))
except NameError:
print('No valid files found.')
sys.exit(1)
else:
parse_torrent_file(scan_path)