...
 
Commits (3)
......@@ -23,6 +23,18 @@ import shutil
import sys
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=[]
for fn in os.listdir("."):
......@@ -47,14 +59,22 @@ if len(new_filenames)!=len(files):
"\x1b[31;1mError\x1b[30;0m: batch rename failed: mismatching line count\n")
sys.exit(1)
for idx,src in enumerate(files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst_base=new_filenames[idx]
if src_base==dst_base: continue
print("%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base))
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1])
shutil.move(src,dst)
for execute in False, True:
if not execute:
print("These are the files that would be renamed:")
for idx,src in enumerate(files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst_base=new_filenames[idx]
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)
......
......@@ -51,6 +51,8 @@ def print_help(f):
"check-consistency [options] [check1 [check2 ... ]]\n"
" Performs a series of consistency check on the klausurarchiv data base.\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"
" {allChecks}\n"
"options:\n"
......
......@@ -326,14 +326,22 @@ if fBatchRename and len(batch_rename_files)>0:
if len(new_filenames)!=len(batch_rename_files):
log("error","batch rename failed: mismatching line count","31;1")
else:
for idx,src in enumerate(batch_rename_files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst_base=new_filenames[idx]
if src_base==dst_base: continue
log("batch renaming","%s \x1b[34;1m->\x1b[30;0m %s"%(src_base,dst_base),"34;1")
dst=os.path.join(os.path.dirname(src),dst_base+os.path.splitext(src)[1])
shutil.move(src,dst)
for execute in False, True:
if not execute:
log("batch renaming","These are the files that would be renamed:")
for idx,src in enumerate(batch_rename_files):
src_base=os.path.splitext(os.path.basename(src))[0]
dst_base=new_filenames[idx]
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:
......
......@@ -97,7 +97,7 @@ def entries():
int(entry.lending.in_date[8:10]))
except ValueError:
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))
yield entry,None,anon,0
continue
......
......@@ -26,7 +26,7 @@ folderreg=klausurarchiv.folders.FolderRegistry.Get()
folders=[]
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 }
......@@ -35,16 +35,16 @@ all_prints={ v.flag: v for v in printreg.scripts_folders }
def print_help(f):
f.write(
"mkprints [prints] [options] (path|id)+\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"
" 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"
" below). If none are set, all prints are created. \n"
"prints:\n"
" {prints}\n"
"options:\n"
" -h|--help\n"
" show this help text and exit normally\n"
" Show this help text and exit normally\n"
" -o|--output <filename>\n"
" set the file name to produce. default: {outfile}\n"
" Set the file name to produce. Default: {outfile}\n"
"".format(
prints="\n ".join([
"%s\n %s"%(v.flag,v.description)
......@@ -70,9 +70,21 @@ try:
folder=folderreg.folders[arg]
if not folder in folders:
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:
raise CLEx("folder not found / stray argument: %s"%arg)
raise CLEx("Folder not found / stray argument: %s"%arg)
elif s=="--output":
outfile=arg
s=None
......@@ -108,9 +120,11 @@ try:
os.chdir(subtmpdir)
try:
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
continue
finally:
os.chdir(tmpdir)
......@@ -132,8 +146,9 @@ try:
" ".join([shlex.quote(v) for v in pieces]),
shlex.quote(outfile)))
print("\nOutput written to \x1b[34;1m%s\x1b[30;0m"%outfile)
finally:
#shutil.rmtree(tmpdir)
os.chdir(cwd)
shutil.rmtree(tmpdir)
......@@ -74,7 +74,7 @@ class AnonymizingClosedLendingProcesses(consistency.ICheck):
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.IdentCount"] = n_unanon
items["AnonymizingClosedLendingProcesses.IdentCountOld"] = n_unanon_old
......