Skip to content

Commit 1928f34

Browse files
committed
new tool
1 parent f035b45 commit 1928f34

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

tools/backup.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cp(dest, gdrive)
4444
cp(dest, idrive)
4545

4646
shortcut = Path(r"C:\Python34\Scripts")
47-
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "StripLastBlankLine.py",
47+
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "StripLastBlankLine.py", "update_git.py",
4848
shortcut / "v.bat", shortcut / "e.bat"]
4949

5050
print("\nCopying tools to Github")

tools/update_git.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#! Py -3
2+
from pathlib import Path
3+
from filecmp import cmpfiles
4+
import sys, os
5+
from sortedcontainers import SortedSet
6+
from betools import *
7+
from pprint import *
8+
9+
gitpath = Path(r"C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut")
10+
examplePath = Path(r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples")
11+
12+
def ignore(lst):
13+
result = [f for f in lst if not str(f).startswith(".git")]
14+
return result
15+
16+
os.chdir(str(examplePath))
17+
book = SortedSet([f for f in Path(".").rglob("*")])
18+
os.chdir(str(gitpath))
19+
git = SortedSet([f for f in Path(".").rglob("*")])
20+
git = ignore(git)
21+
22+
23+
@CmdLine('g')
24+
def copy_to_git():
25+
"Write batch file to copy missing files to git directory"
26+
exclude = ["Book.txt", "Git.txt", "togit.bat"]
27+
os.chdir(str(examplePath))
28+
with Path("togit.bat").open("w") as togit:
29+
tocopy = [e for e in book if e not in git]
30+
for e in exclude:
31+
tocopy = [t for t in tocopy if not str(t).endswith(e)]
32+
for tc in tocopy:
33+
togit.write("copy " + str(tc) + " " + str(gitpath / tc) + "\n")
34+
if Path("togit.bat").stat().st_size == 0:
35+
Path("togit.bat").unlink()
36+
37+
38+
def retain(lst):
39+
keep = ["README.md", "go.bat", "clean.bat"]
40+
result = [f for f in lst if not str(f).startswith("tools")]
41+
result = [f for f in result if not f.is_dir()]
42+
for k in keep:
43+
result = [f for f in result if not str(f).endswith(k)]
44+
return result
45+
46+
47+
@CmdLine('c')
48+
def clean():
49+
"Write batch file to remove unused files from git directory"
50+
os.chdir(str(gitpath))
51+
with Path("clean.bat").open("w") as clean:
52+
toclean = retain([g for g in git if g not in book])
53+
for tc in toclean:
54+
clean.write("del " + str(tc) + "\n")
55+
if Path("clean.bat").stat().st_size == 0:
56+
Path("clean.bat").unlink()
57+
58+
59+
# def print_diff_files(dcmp, outfile):
60+
# for name in dcmp.diff_files:
61+
# outfile.write("diff_file %s found in %s and %s\n" % (name, dcmp.left,
62+
# dcmp.right))
63+
# for sub_dcmp in dcmp.subdirs.values():
64+
# print_diff_files(sub_dcmp, outfile)
65+
66+
@CmdLine('u')
67+
def update_to_git():
68+
"Write batch file to copy out-of-date files to git directory"
69+
os.chdir(str(examplePath))
70+
common = [str(b) for b in book if not b.is_dir()]
71+
match, mismatch, errors = cmpfiles(str(examplePath), str(gitpath), common, False)
72+
with Path("update.bat").open('w') as outfile:
73+
outfile.write("\n" + ruler("match"))
74+
outfile.write(pformat(match))
75+
outfile.write("\n" + ruler("mismatch"))
76+
outfile.write(pformat(mismatch))
77+
outfile.write("\n" + ruler("errors"))
78+
outfile.write(pformat(errors))
79+
for f in mismatch:
80+
if not (f.endswith(".java") or
81+
f.endswith(".py") or
82+
f.endswith(".cpp") or
83+
f.endswith("build.xml")):
84+
print(f)
85+
86+
87+
if __name__ == '__main__':
88+
CmdLine.run()

0 commit comments

Comments
 (0)