-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
149 additions
and
13 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,79 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys, os, re, json, argparse, time, pytz | ||
import console | ||
|
||
from datetime import datetime, timedelta | ||
from difflib import unified_diff, ndiff | ||
|
||
#_____________________________________________________ | ||
def argue(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-v', '--verbose', action='store_true') | ||
parser.add_argument('lhs') | ||
parser.add_argument('rhs') | ||
args = parser.parse_args() | ||
if args.verbose: | ||
json.dump(vars(args),sys.stderr,indent=4) | ||
return args | ||
|
||
#_____________________________________________________ | ||
def sn(x): | ||
return '%s\n'%x | ||
|
||
#_____________________________________________________ | ||
def modified(f): | ||
lmt = os.path.getmtime(f) | ||
est = pytz.timezone('Australia/Sydney') | ||
gmt = pytz.timezone('GMT') | ||
tzf = '%Y-%m-%d %H:%M:%S' | ||
gdt = datetime.utcfromtimestamp(lmt) | ||
gdt = gmt.localize(gdt) | ||
adt = est.normalize(gdt.astimezone(est)) | ||
return adt.strftime(tzf) | ||
|
||
#_____________________________________________________ | ||
def diff(lhs,rhs): | ||
if not os.path.isfile(lhs): | ||
sys.stderr.write('%s not a file\n'%lhs) | ||
sys.exit(1) | ||
if os.path.isdir(rhs): | ||
rhs = '%s/%s'%(rhs,os.path.basename(lhs)) | ||
if not os.path.isfile(rhs): | ||
sys.stderr.write('%s not a file\n'%rhs) | ||
sys.exit(1) | ||
|
||
flhs = open(lhs).readlines() | ||
frhs = open(rhs).readlines() | ||
|
||
diffs = unified_diff( | ||
flhs, | ||
frhs, | ||
fromfile=lhs, | ||
tofile=rhs, | ||
fromfiledate=modified(lhs), | ||
tofiledate=modified(rhs) | ||
) | ||
for line in diffs: | ||
if line.startswith('+'): | ||
console.set_color(0,1,0) | ||
if line.startswith('-'): | ||
console.set_color(0,0,1) | ||
sys.stdout.write(line) | ||
console.set_color(1,1,1) | ||
return | ||
|
||
#_____________________________________________________ | ||
def main(): | ||
console.clear() | ||
args = argue() | ||
diff( | ||
args.lhs.rstrip('/'), | ||
args.rhs.rstrip('/') | ||
) | ||
return | ||
|
||
#_____________________________________________________ | ||
if __name__ == '__main__': main() | ||
|
||
|
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,45 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys, os, re, json, argparse, time, pytz | ||
import console | ||
from datetime import datetime, timedelta | ||
from difflib import unified_diff, ndiff | ||
|
||
def argue(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-v', '--verbose', action='store_true') | ||
parser.add_argument('-s', '--symbolic', action='store_true') | ||
parser.add_argument('-f', '--force', action='store_true') | ||
parser.add_argument('lhs') | ||
parser.add_argument('rhs') | ||
args = parser.parse_args() | ||
if args.verbose: | ||
json.dump(vars(args),sys.stderr,indent=4) | ||
return args | ||
|
||
def ln(lhs,rhs,symbolic=False): | ||
if not os.path.exists(lhs): | ||
sys.stderr.write('%s not found\n'%lhs) | ||
sys.exit(1) | ||
if os.path.isdir(rhs): | ||
rhs = '%s/%s'%(rhs,os.path.basename(lhs)) | ||
if os.path.isfile(rhs): | ||
sys.stderr.write('%s already exists\n'%rhs) | ||
sys.exit(1) | ||
if os.path.islink(rhs): | ||
sys.stderr.write('%s already linked\n'%rhs) | ||
sys.exit(1) | ||
|
||
if symbolic: | ||
os.symlink(lhs,rhs) | ||
else: | ||
os.link(lhs,rhs) | ||
return | ||
|
||
def main(): | ||
console.clear() | ||
args = argue() | ||
ln(args.lhs,args.rhs,args.symbolic) | ||
return | ||
|
||
if __name__ == '__main__': main() |
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