Skip to content

Commit

Permalink
Allow multiple file patterns on the command line.
Browse files Browse the repository at this point in the history
When debugging desyncs, it's useful to be able to re-run a bunch of
previous failures. For example:

  python regression-test $(cat previous-fails.txt)

To be able to do this it's necessary to be able to specify multiple
patterns on the command line. This is in keeping with other Unix tools
that do the same.
  • Loading branch information
fragglet committed Jun 9, 2015
1 parent 4bb0c9b commit 80ff0cb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import subprocess
import fcntl
from select import select
from fnmatch import fnmatch
import fnmatch
import zipfile
import shutil
import os
import re

from config import *

Expand Down Expand Up @@ -298,8 +299,13 @@ def process_zipfile(filename, dir, callback):

zf.close()

def find_all_zips(path, pattern):
def patterns_to_regexp(patterns):
"""Given a list of patterns, make a regexp that matches any one."""
regexps = [fnmatch.translate(p) for p in patterns]
return re.compile("(%s)" % ("|".join(regexps)))

def find_all_zips(path, regexp):
"""Find .zip files in given path matching the given regexp."""
result = []

for dirpath, dirnames, filenames in os.walk(path):
Expand All @@ -313,21 +319,20 @@ def find_all_zips(path, pattern):
if identify_game_type(relpath) is None:
continue

if fnmatch(relpath, pattern):
result.append(relpath)

return result
if regexp.match(relpath):
yield relpath

def process_all_zips(path, callback):

if len(sys.argv) > 1:
pattern = sys.argv[1]
patterns = sys.argv[1:]
else:
pattern = "*"
patterns = ["*"]

# Find the ZIP files to process.

zips = find_all_zips(path, pattern)
regexp = patterns_to_regexp(patterns)
zips = list(find_all_zips(path, regexp))

# Variables used by the processing function.

Expand Down

0 comments on commit 80ff0cb

Please sign in to comment.