...
 
Commits (3)
...@@ -23,6 +23,18 @@ import shutil ...@@ -23,6 +23,18 @@ import shutil
import sys import sys
import tempfile import tempfile
if len(sys.argv) > 1:
sys.stderr.write(
"batch-rename\n"
"Invoke vim on a temporary file containing all file names in the current\n"
"directory. The names can be edited so the files will be renamed\n"
"accordingly.\n"
"\x1b[33;1mWarning\x1b[30;0m: This tool ignores naming schemes! You might\n"
"want to use rename or apply-rename instead!\n"
"\x1b[33;1mWarning\x1b[30;0m: This tool can also rename symlinks, but\n"
"will not change their targets.\n")
sys.exit(1)
files=[] files=[]
for fn in os.listdir("."): for fn in os.listdir("."):
...@@ -47,14 +59,22 @@ if len(new_filenames)!=len(files): ...@@ -47,14 +59,22 @@ if len(new_filenames)!=len(files):
"\x1b[31;1mError\x1b[30;0m: batch rename failed: mismatching line count\n") "\x1b[31;1mError\x1b[30;0m: batch rename failed: mismatching line count\n")
sys.exit(1) sys.exit(1)
for idx,src in enumerate(files): for execute in False, True:
src_base=os.path.splitext(os.path.basename(src))[0] if not execute:
dst_base=new_filenames[idx] print("These are the files that would be renamed:")
if src_base==dst_base: continue
print("%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base)) for idx,src in enumerate(files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1]) dst_base=new_filenames[idx]
shutil.move(src,dst) if src_base==dst_base: continue
if not execute:
print("%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base))
else:
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1])
shutil.move(src,dst)
if not execute:
input("Press Enter to continue, Ctrl+C to abort.\n")
os.unlink(fnEdit) os.unlink(fnEdit)
......
...@@ -51,6 +51,8 @@ def print_help(f): ...@@ -51,6 +51,8 @@ def print_help(f):
"check-consistency [options] [check1 [check2 ... ]]\n" "check-consistency [options] [check1 [check2 ... ]]\n"
" Performs a series of consistency check on the klausurarchiv data base.\n" " Performs a series of consistency check on the klausurarchiv data base.\n"
" If no checks are selected, all of them are executed.\n" " If no checks are selected, all of them are executed.\n"
" See the documentation on klausurarchiv.consistency for details on the\n"
" statistics.\n"
"available checks:\n" "available checks:\n"
" {allChecks}\n" " {allChecks}\n"
"options:\n" "options:\n"
......
...@@ -326,14 +326,22 @@ if fBatchRename and len(batch_rename_files)>0: ...@@ -326,14 +326,22 @@ if fBatchRename and len(batch_rename_files)>0:
if len(new_filenames)!=len(batch_rename_files): if len(new_filenames)!=len(batch_rename_files):
log("error","batch rename failed: mismatching line count","31;1") log("error","batch rename failed: mismatching line count","31;1")
else: else:
for idx,src in enumerate(batch_rename_files): for execute in False, True:
src_base=os.path.splitext(os.path.basename(src))[0] if not execute:
dst_base=new_filenames[idx] log("batch renaming","These are the files that would be renamed:")
if src_base==dst_base: continue
log("batch renaming","%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base),"34;1") for idx,src in enumerate(batch_rename_files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1]) dst_base=new_filenames[idx]
shutil.move(src,dst) if src_base==dst_base: continue
if not execute:
log("batch renaming","%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base),"34;1")
else:
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1])
shutil.move(src,dst)
if not execute:
input("Press Enter to continue, Ctrl+C to abort.\n")
if len(renaming_data)>0 and not fQuiet: if len(renaming_data)>0 and not fQuiet:
......
...@@ -97,7 +97,7 @@ def entries(): ...@@ -97,7 +97,7 @@ def entries():
int(entry.lending.in_date[8:10])) int(entry.lending.in_date[8:10]))
except ValueError: except ValueError:
sys.stderr.write( sys.stderr.write(
"\x1b[33;1mWarning\x1b[30;0m: entry %s in file %s has invalid date\n" "\x1b[33;1mWarning\x1b[30;0m: entry %s in file %s has invalid in_date\n"
%(entry.lidx,entry.filename)) %(entry.lidx,entry.filename))
yield entry,None,anon,0 yield entry,None,anon,0
continue continue
......
...@@ -26,7 +26,7 @@ folderreg=klausurarchiv.folders.FolderRegistry.Get() ...@@ -26,7 +26,7 @@ folderreg=klausurarchiv.folders.FolderRegistry.Get()
folders=[] folders=[]
prints=[] prints=[]
outfile="prints.pdf" outfile=os.path.join(os.getenv("KA_ROOT"),"prints.pdf")
all_prints={ v.flag: v for v in printreg.scripts_folders } all_prints={ v.flag: v for v in printreg.scripts_folders }
...@@ -35,16 +35,16 @@ all_prints={ v.flag: v for v in printreg.scripts_folders } ...@@ -35,16 +35,16 @@ all_prints={ v.flag: v for v in printreg.scripts_folders }
def print_help(f): def print_help(f):
f.write( f.write(
"mkprints [prints] [options] (path|id)+\n" "mkprints [prints] [options] (path|id)+\n"
" creates a pdf containing printouts for one or more physical folders.\n" " Creates a PDF containing printouts for one or more physical folders.\n"
" the kind of printouts to be created can be specified as switches (see\n" " The kind of printouts to be created can be specified as switches (see\n"
" below). If none are set, all prints are created. \n" " below). If none are set, all prints are created. \n"
"prints:\n" "prints:\n"
" {prints}\n" " {prints}\n"
"options:\n" "options:\n"
" -h|--help\n" " -h|--help\n"
" show this help text and exit normally\n" " Show this help text and exit normally\n"
" -o|--output <filename>\n" " -o|--output <filename>\n"
" set the file name to produce. default: {outfile}\n" " Set the file name to produce. Default: {outfile}\n"
"".format( "".format(
prints="\n ".join([ prints="\n ".join([
"%s\n %s"%(v.flag,v.description) "%s\n %s"%(v.flag,v.description)
...@@ -70,9 +70,21 @@ try: ...@@ -70,9 +70,21 @@ try:
folder=folderreg.folders[arg] folder=folderreg.folders[arg]
if not folder in folders: if not folder in folders:
folders.append(folder) folders.append(folder)
# todo: resolve folder paths elif os.path.isdir(arg):
realpath=os.path.realpath(arg)
split=os.path.basename(realpath).split(" - ")
if len(split) != 3:
raise CLEx("Folder ID not found in path: %s"%arg)
fid=split[2]
folder=folderreg.folders[fid]
if folder.path != realpath:
raise CLEx(("Folder mismatch: Found ID {id} for {arg}\n"
"Folder registry reports other path {path}"
).format(id=fid,arg=arg,path=folder.path))
if not folder in folders:
folders.append(folder)
else: else:
raise CLEx("folder not found / stray argument: %s"%arg) raise CLEx("Folder not found / stray argument: %s"%arg)
elif s=="--output": elif s=="--output":
outfile=arg outfile=arg
s=None s=None
...@@ -108,9 +120,11 @@ try: ...@@ -108,9 +120,11 @@ try:
os.chdir(subtmpdir) os.chdir(subtmpdir)
try: try:
res=printer.handle_folders(folders) res=printer.handle_folders(folders)
except: except Exception:
sys.stderr.write(
"\x1b[31;1mError\x1b[30;0m: An exception occured while handling %s:\n"
%flag)
raise raise
continue
finally: finally:
os.chdir(tmpdir) os.chdir(tmpdir)
...@@ -132,8 +146,9 @@ try: ...@@ -132,8 +146,9 @@ try:
" ".join([shlex.quote(v) for v in pieces]), " ".join([shlex.quote(v) for v in pieces]),
shlex.quote(outfile))) shlex.quote(outfile)))
print("\nOutput written to \x1b[34;1m%s\x1b[30;0m"%outfile)
finally: finally:
#shutil.rmtree(tmpdir)
os.chdir(cwd) os.chdir(cwd)
shutil.rmtree(tmpdir)
...@@ -74,7 +74,7 @@ class AnonymizingClosedLendingProcesses(consistency.ICheck): ...@@ -74,7 +74,7 @@ class AnonymizingClosedLendingProcesses(consistency.ICheck):
if age>60: n_unanon_very_old+=1 if age>60: n_unanon_very_old+=1
items["AnonymizingClosedLendingProcesses.TotlaCount"] = n_total items["AnonymizingClosedLendingProcesses.TotalCount"] = n_total
items["AnonymizingClosedLendingProcesses.AnonCount"] = n_anon items["AnonymizingClosedLendingProcesses.AnonCount"] = n_anon
items["AnonymizingClosedLendingProcesses.IdentCount"] = n_unanon items["AnonymizingClosedLendingProcesses.IdentCount"] = n_unanon
items["AnonymizingClosedLendingProcesses.IdentCountOld"] = n_unanon_old items["AnonymizingClosedLendingProcesses.IdentCountOld"] = n_unanon_old
......