-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomen-extcase.py
executable file
·88 lines (73 loc) · 3.15 KB
/
nomen-extcase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ============================================================================
# Nomen - Multi-purpose rename tool
# Extension Case Converter script
# Copyright (C) 2018 by Ralf Kilian
# Distributed under the MIT License (https://opensource.org/licenses/MIT)
#
# GitHub: https://github.com/urbanware-org/nomen
# GitLab: https://gitlab.com/urbanware-org/nomen
# ============================================================================
import os
import sys
def main():
from core import clap
from core import common
from core import extren
try:
p = clap.Parser()
except Exception as e:
print("%s: error: %s" % (os.path.basename(sys.argv[0]), e))
sys.exit(1)
p.set_description("Convert the case of the extension of all files "
"inside a directory and (if requested) in all of its "
"sub-directories.")
p.set_epilog("Further information and usage examples can be found "
"inside the documentation file for this script.")
# Required arguments
p.add_predef("-c", "--case", "target extension case", "case",
["lower", "title", "upper"], True)
p.add_avalue("-d", "--directory", "directory that contains the files "
"to process", "directory", None, True)
p.add_predef("-m", "--conflict-mode", "conflict mode (in case of "
"duplicate file names)", "conflict_mode", ["rename", "skip"],
True)
# Optional arguments
p.add_switch(None, "--confirm", "skip the confirmation prompt and "
"instantly rename files", "confirm", True, False)
p.add_switch("-h", "--help", "print this help message and exit", None,
True, False)
p.add_switch(None, "--ignore-symlinks", "ignore symbolic links",
"ignore_symlinks", True, False)
p.add_switch("-r", "--recursive", "process the given directory "
"recursively", "recursive", True, False)
p.add_avalue(None, "--simulate", "simulate the rename process and "
"write the details into a report file", "report_file", None,
False)
p.add_switch(None, "--version", "print the version number and exit", None,
True, False)
if len(sys.argv) == 1:
p.error("At least one required argument is missing.")
elif ("-h" in sys.argv) or ("--help" in sys.argv):
p.print_help()
sys.exit(0)
elif "--version" in sys.argv:
print(extren.get_version())
sys.exit(0)
args = p.parse_args()
if args.confirm and args.report_file is not None:
p.error("The confirm and the simulate argument cannot be given at "
"the same time.")
try:
if not args.confirm and args.report_file is None:
if not common.confirm_notice():
sys.exit(0)
extren.convert_case(args.directory, args.case, args.conflict_mode,
args.recursive, args.report_file,
args.ignore_symlinks)
except Exception as e:
p.error(e)
if __name__ == "__main__":
main()
# EOF