-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved to the cli package - pep8 cleanup
- Loading branch information
Mark Fiers
committed
Oct 23, 2012
1 parent
8d98191
commit 36041c8
Showing
2 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import argparse | ||
import subprocess as sp | ||
|
||
parser = argparse.ArgumentParser(description='run recursively') | ||
parser.add_argument('--bg', dest='background', action='store_true', | ||
default=False, | ||
help='run each job in the background') | ||
parser.add_argument('-d', dest='depth', default=0, type=int, | ||
help='depth: 1 means run only in first ' + | ||
'level subdirs, 2 only in second level, and so on') | ||
parser.add_argument('-t', dest='test', default=False, | ||
help='test run', action='store_true') | ||
parser.add_argument('command', nargs='+') | ||
args = parser.parse_args() | ||
|
||
|
||
def moar(): | ||
cl = " ".join(args.command).strip() | ||
if args.background and cl[-1] != '&': | ||
cl = '( ' + cl + ' )& ' | ||
|
||
print 'executing:', cl | ||
|
||
base = os.path.abspath(os.getcwd()) | ||
|
||
if base[-1] == '/': | ||
base = base[:-1] | ||
|
||
for path, dirs, files in os.walk(base): | ||
toRemove = [x for x in dirs if x[0] in ['.', '_']] | ||
[dirs.remove(x) for x in toRemove] | ||
localpath = path.replace(base, '') | ||
level = len(localpath.split('/')) - 1 | ||
|
||
if args.depth and args.depth != level: | ||
continue | ||
|
||
if args.test: | ||
print 'would executed in', localpath | ||
print ' ', cl | ||
else: | ||
print 'executing in %s' % localpath | ||
P = sp.Popen(cl, cwd=path, shell=True) | ||
P.wait() | ||
|
||
if __name__ == '__main__': | ||
moar() |