Skip to content
Snippets Groups Projects
Commit b7ff0357 authored by Dennis Baurichter's avatar Dennis Baurichter
Browse files

rename: Replace --commit by --move

The option moves files into the next directory. --commit might be
confused to implicitly calling the commit tool (which is not done by
rename).
parent 55f6cdda
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ etc.) interactively.
After naming all exams, they are moved into the `10-benannt` directory by
invoking
```
rename -I -c
rename -I -m
```
in the working directory.
......
......@@ -17,12 +17,12 @@ pdfViewers=set()
pdfViewersAll= [ "okular", "qpdfview" ]
fDirectory=False
fCreateSourceDirectories=False
fCommit=False
fMove=False
fRecurse=False
fFinal=False
fInbox=False
files=[]
commitDir=None
moveDir=None
setFields=dict()
validFields= [ "lecture", "examiner", "examType" ]
......@@ -48,16 +48,16 @@ def print_help(f):
" primary tool for the task of preparing files from 00-inbox for insertion\n"
" into our database. \n"
"examples: \n"
" rename [-c|--commit] --create-source-directories [directory]\n"
" rename [-m|--move] --create-source-directories [directory]\n"
" finds all PDF files in [directory], or the current one if none was \n"
" specified. Then a new directory is created for each pdf file with\n"
" the same base name and extension \".source\".\n"
" rename [-c|--commit] -D [directory]\n"
" rename [-m|--move] -D [directory]\n"
" finds all PDF files in [directory] like the previous use case. \n"
" Then shows a dialog for renaming all of these into the proper \n"
" naming scheme. Whenever a pdf is renamed, its source directory is \n"
" either deleted (if it is empty) or renamed accordingly. \n"
" If the commit option is specified, renamed files and directories \n"
" If the move option is specified, renamed files and directories \n"
" are moved into 10-benannt.\n"
"options:\n"
" -h|--help\n"
......@@ -75,7 +75,7 @@ def print_help(f):
" -R|--recurse\n"
" when processing entire directories (-S or -D), also process all \n"
" descendant directories \n"
" -c|--commit \n"
" -m|--move \n"
" whenever renaming takes place, also move the renamed files to \n"
" 10-benannt.\n"
" When creating source directories (-S), move all non-pdf files with \n"
......@@ -91,7 +91,7 @@ def print_help(f):
" Just rename all files and directories in the current directory \n"
" without checking the extension and without recursion. \n"
" Cannot be used together with -S, -D, -R or -f. \n"
" If specified with -c, no renaming is performed. Instead, all \n"
" If specified with -m, no renaming is performed. Instead, all \n"
" correctly named pdf files and directories are moved to 10-benannt. \n"
" Also, for each directory, a PDF is picked from its content to be \n"
" moved alongside it (correctly named, of course). If no such PDF \n"
......@@ -123,7 +123,7 @@ try:
elif arg in {"-S","--create-source-directories"}: fCreateSourceDirectories=True
elif arg in {"-D","--directory"}: fDirectory=True
elif arg in {"-R","--recurse"}: fRecurse=True
elif arg in {"-c","--commit"}: fCommit=True
elif arg in {"-m","--move"}: fMove=True
elif arg in {"--pdf-viewer"}: s="--pdf-viewer"
elif arg in {"-f","--final"}: fFinal=True
elif arg in {"-I","--inbox"}: fInbox=True
......@@ -171,9 +171,9 @@ try:
if rootDir==None:
raise CLEx("no KA_ROOT specified")
if fCommit:
commitDir=os.path.join(rootDir,"10-benannt")
if not os.path.exists(commitDir):
if fMove:
moveDir=os.path.join(rootDir,"10-benannt")
if not os.path.exists(moveDir):
raise CLEx("Bad KA_ROOT: $KA_ROOT/10-benannt does not exist")
except CLEx as e:
print_help(sys.stderr)
......@@ -227,7 +227,7 @@ def pdfFiles():
yield fn
if fInbox:
if fCommit:
if fMove:
ops=list()
target_dir=os.path.join(os.getenv("KA_ROOT"),"10-benannt")
perfect=True
......@@ -336,7 +336,7 @@ elif fCreateSourceDirectories:
source_fn=os.path.splitext(fn)[0]+".source"
if not os.path.exists(source_fn):
os.system("mkdir -p %s"%shlex.quote(source_fn))
if fCommit:
if fMove:
(fd,fb)=os.path.split(fn)
fb=os.path.splitext(fb)[0]
for fn1 in os.listdir(os.path.dirname(fn)):
......@@ -397,7 +397,7 @@ else:
else:
if fCommit: target_dir=commitDir
if fMove: target_dir=moveDir
else: target_dir=os.path.dirname(fn)
ops.add( (fn,os.path.join(target_dir,trg)) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment