chname 2.1.5__tar.gz → 2.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chname might be problematic. Click here for more details.
- {chname-2.1.5 → chname-2.1.6}/PKG-INFO +12 -6
- {chname-2.1.5 → chname-2.1.6}/pyproject.toml +12 -3
- {chname-2.1.5 → chname-2.1.6}/src/chname/__main__.py +29 -28
- {chname-2.1.5 → chname-2.1.6}/LICENSE +0 -0
- {chname-2.1.5 → chname-2.1.6}/README.md +0 -0
- {chname-2.1.5 → chname-2.1.6}/src/chname/__init__.py +0 -0
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: chname
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.6
|
|
4
4
|
Summary: Renames files in powerful ways
|
|
5
|
-
License: MIT
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: rename,file,batch,bulk,utility,command-line,cli
|
|
6
8
|
Author: Steve Scholnick
|
|
7
9
|
Author-email: scholnicks@gmail.com
|
|
8
10
|
Requires-Python: >=3.13
|
|
9
|
-
Classifier:
|
|
10
|
-
Classifier:
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
11
13
|
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
12
16
|
Requires-Dist: docopt-ng (>=0.9.0,<0.10.0)
|
|
13
|
-
Project-URL:
|
|
17
|
+
Project-URL: Homepage, https://pypi.org/project/chname/
|
|
18
|
+
Project-URL: Issues, https://github.com/scholnicks/chname/issues
|
|
19
|
+
Project-URL: Repository, https://github.com/scholnicks/chname/
|
|
14
20
|
Description-Content-Type: text/markdown
|
|
15
21
|
|
|
16
22
|
# chname
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "chname"
|
|
3
|
-
version = "2.1.
|
|
3
|
+
version = "2.1.6"
|
|
4
4
|
description = "Renames files in powerful ways"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Steve Scholnick",email = "scholnicks@gmail.com"}
|
|
@@ -12,14 +12,23 @@ requires-python = ">=3.13"
|
|
|
12
12
|
dependencies = [
|
|
13
13
|
"docopt-ng (>=0.9.0,<0.10.0)"
|
|
14
14
|
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Topic :: Utilities"
|
|
21
|
+
]
|
|
22
|
+
keywords = ["rename", "file", "batch", "bulk", "utility", "command-line", "cli"]
|
|
15
23
|
|
|
16
24
|
[project.urls]
|
|
17
|
-
|
|
25
|
+
homepage="https://pypi.org/project/chname/"
|
|
26
|
+
repository="https://github.com/scholnicks/chname/"
|
|
27
|
+
Issues = "https://github.com/scholnicks/chname/issues"
|
|
18
28
|
|
|
19
29
|
[tool.poetry]
|
|
20
30
|
packages = [{include = "chname", from = "src"}]
|
|
21
31
|
|
|
22
|
-
|
|
23
32
|
[build-system]
|
|
24
33
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
25
34
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -38,12 +38,13 @@ import sys
|
|
|
38
38
|
|
|
39
39
|
from docopt import docopt
|
|
40
40
|
|
|
41
|
-
arguments = {}
|
|
41
|
+
arguments: dict = {}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
def main() -> None:
|
|
44
45
|
"""Main Method"""
|
|
45
46
|
global arguments
|
|
46
|
-
arguments = docopt(__doc__, version="chname 2.1.
|
|
47
|
+
arguments = docopt(__doc__, version="chname 2.1.6")
|
|
47
48
|
|
|
48
49
|
if arguments["--test"]:
|
|
49
50
|
arguments["--verbose"] = True
|
|
@@ -51,7 +52,7 @@ def main():
|
|
|
51
52
|
flux(arguments["<files>"])
|
|
52
53
|
|
|
53
54
|
|
|
54
|
-
def flux(files):
|
|
55
|
+
def flux(files: list[str]) -> None:
|
|
55
56
|
"""Renames the specified files"""
|
|
56
57
|
|
|
57
58
|
if arguments["--usage"] or not files:
|
|
@@ -76,9 +77,9 @@ def flux(files):
|
|
|
76
77
|
sys.exit(0)
|
|
77
78
|
|
|
78
79
|
|
|
79
|
-
def nameFilesByInputFile(files):
|
|
80
|
+
def nameFilesByInputFile(files) -> None:
|
|
80
81
|
"""Names files by using an input text file"""
|
|
81
|
-
extension = calculateExtension(files)
|
|
82
|
+
extension: str = calculateExtension(files)
|
|
82
83
|
|
|
83
84
|
with open(arguments["--titles"], "r") as fp:
|
|
84
85
|
exportFileNames = [line.strip() for line in fp if line.strip()]
|
|
@@ -90,12 +91,12 @@ def nameFilesByInputFile(files):
|
|
|
90
91
|
)
|
|
91
92
|
)
|
|
92
93
|
|
|
93
|
-
filenameTemplate = (
|
|
94
|
+
filenameTemplate: str = (
|
|
94
95
|
r"{num:02d} - {filename}{extension}" if len(files) < 100 else r"{num:04d} - {filename}{extension}"
|
|
95
96
|
)
|
|
96
|
-
index = 1
|
|
97
|
+
index: int = 1
|
|
97
98
|
for currentFilePath, newFileName in zip(files, exportFileNames):
|
|
98
|
-
newFilePath = os.path.join(
|
|
99
|
+
newFilePath: str = os.path.join(
|
|
99
100
|
os.path.dirname(currentFilePath),
|
|
100
101
|
filenameTemplate.format(num=index, filename=newFileName, extension=extension),
|
|
101
102
|
)
|
|
@@ -103,48 +104,48 @@ def nameFilesByInputFile(files):
|
|
|
103
104
|
index += 1
|
|
104
105
|
|
|
105
106
|
|
|
106
|
-
def orderFiles(files):
|
|
107
|
+
def orderFiles(files) -> None:
|
|
107
108
|
"""Orders the files"""
|
|
108
|
-
filenameTemplate = r"{num:02d} - {filename}" if len(files) < 100 else r"{num:04d} - {filename}"
|
|
109
|
+
filenameTemplate: str = r"{num:02d} - {filename}" if len(files) < 100 else r"{num:04d} - {filename}"
|
|
109
110
|
|
|
110
111
|
for index, currentFilePath in enumerate(sorted(files), 1):
|
|
111
|
-
newFilePath = os.path.join(
|
|
112
|
+
newFilePath: str = os.path.join(
|
|
112
113
|
os.path.dirname(currentFilePath),
|
|
113
114
|
filenameTemplate.format(num=index, filename=os.path.basename(currentFilePath)),
|
|
114
115
|
)
|
|
115
116
|
rename_file(currentFilePath, newFilePath)
|
|
116
117
|
|
|
117
118
|
|
|
118
|
-
def randomizeFiles(files):
|
|
119
|
+
def randomizeFiles(files) -> None:
|
|
119
120
|
"""randomly shuffles a list of files with the same extension"""
|
|
120
121
|
|
|
121
122
|
# determine the extension
|
|
122
|
-
extension = calculateExtension(files)
|
|
123
|
+
extension: str = calculateExtension(files)
|
|
123
124
|
|
|
124
125
|
# do the shuffle
|
|
125
126
|
random.shuffle(files)
|
|
126
127
|
|
|
127
|
-
prefix = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
128
|
+
prefix: str = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
128
129
|
|
|
129
130
|
# rename the files in numeric order
|
|
130
131
|
for index, filename in enumerate(files, 1):
|
|
131
|
-
new_file_name = os.path.join(
|
|
132
|
+
new_file_name: str = os.path.join(
|
|
132
133
|
os.path.dirname(filename),
|
|
133
134
|
"{prefix}_{num:04d}{extension}".format(prefix=prefix, num=index, extension=extension),
|
|
134
135
|
)
|
|
135
136
|
rename_file(filename, new_file_name)
|
|
136
137
|
|
|
137
138
|
|
|
138
|
-
def mergeFiles(files):
|
|
139
|
+
def mergeFiles(files) -> None:
|
|
139
140
|
"""reorders a set of files in order in a target directory"""
|
|
140
141
|
|
|
141
142
|
if not arguments["--directory"]:
|
|
142
143
|
raise SystemExit("--directory must be set")
|
|
143
144
|
|
|
144
145
|
# determine the extension
|
|
145
|
-
extension = calculateExtension(files)
|
|
146
|
+
extension: str = calculateExtension(files)
|
|
146
147
|
|
|
147
|
-
prefix = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
148
|
+
prefix: str = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
148
149
|
|
|
149
150
|
# rename the files in argument specified order
|
|
150
151
|
for index, filename in enumerate(files, 1):
|
|
@@ -154,23 +155,23 @@ def mergeFiles(files):
|
|
|
154
155
|
rename_file(filename, new_file_name)
|
|
155
156
|
|
|
156
157
|
|
|
157
|
-
def calculateExtension(files):
|
|
158
|
+
def calculateExtension(files) -> str:
|
|
158
159
|
"""determines a single extension"""
|
|
159
|
-
extensions = set((os.path.splitext(f)[1].lower() for f in files))
|
|
160
|
+
extensions: set[str] = set((os.path.splitext(f)[1].lower() for f in files))
|
|
160
161
|
if len(extensions) > 1:
|
|
161
162
|
raise SystemExit("Only one extension allowed. Found: {}".format(", ".join(extensions)))
|
|
162
163
|
|
|
163
164
|
return extensions.pop()
|
|
164
165
|
|
|
165
166
|
|
|
166
|
-
def performRenameOperation(fileName):
|
|
167
|
+
def performRenameOperation(fileName) -> None:
|
|
167
168
|
"""Performs a renaming operation on the specified filename"""
|
|
168
169
|
if not os.path.exists(fileName):
|
|
169
170
|
if not arguments["--quiet"]:
|
|
170
171
|
print("{} does not exist, skipping.".format(fileName), file=sys.stderr)
|
|
171
172
|
return
|
|
172
173
|
|
|
173
|
-
newFileName = fileName
|
|
174
|
+
newFileName: str = fileName
|
|
174
175
|
|
|
175
176
|
if arguments["--lower"]:
|
|
176
177
|
newFileName = newFileName.lower()
|
|
@@ -196,7 +197,7 @@ def performRenameOperation(fileName):
|
|
|
196
197
|
rename_file(fileName, newFileName)
|
|
197
198
|
|
|
198
199
|
|
|
199
|
-
def rename_file(oldName, newName):
|
|
200
|
+
def rename_file(oldName, newName) -> None:
|
|
200
201
|
"""Performs the actual file rename"""
|
|
201
202
|
if arguments["--verbose"]:
|
|
202
203
|
print("Renaming {} to {}".format(oldName, newName))
|
|
@@ -205,7 +206,7 @@ def rename_file(oldName, newName):
|
|
|
205
206
|
os.rename(oldName, newName)
|
|
206
207
|
|
|
207
208
|
|
|
208
|
-
def substitute(fileName, pattern):
|
|
209
|
+
def substitute(fileName, pattern) -> str:
|
|
209
210
|
"""Performs the pattern substitution"""
|
|
210
211
|
try:
|
|
211
212
|
(old, new) = re.match(r"^(.*)/(.*)$", pattern).groups()
|
|
@@ -214,7 +215,7 @@ def substitute(fileName, pattern):
|
|
|
214
215
|
raise SystemExit("chname: Illegal substitute pattern. Pattern must be old/new")
|
|
215
216
|
|
|
216
217
|
|
|
217
|
-
def fixNumbers(fileName, delimiter, numberLength):
|
|
218
|
+
def fixNumbers(fileName, delimiter, numberLength) -> str:
|
|
218
219
|
"""Fixes the numeric part of a filename"""
|
|
219
220
|
if delimiter not in fileName:
|
|
220
221
|
return fileName
|
|
@@ -222,7 +223,7 @@ def fixNumbers(fileName, delimiter, numberLength):
|
|
|
222
223
|
(base, extension) = os.path.splitext(fileName)
|
|
223
224
|
(prefix, number) = base.split(delimiter, 2)
|
|
224
225
|
|
|
225
|
-
sequenceValue = number
|
|
226
|
+
sequenceValue: str = number
|
|
226
227
|
|
|
227
228
|
for i in range(len(number), int(numberLength)):
|
|
228
229
|
sequenceValue = "0" + sequenceValue
|
|
@@ -230,7 +231,7 @@ def fixNumbers(fileName, delimiter, numberLength):
|
|
|
230
231
|
return prefix + delimiter + sequenceValue + extension
|
|
231
232
|
|
|
232
233
|
|
|
233
|
-
def usage():
|
|
234
|
+
def usage() -> None:
|
|
234
235
|
print(
|
|
235
236
|
__doc__
|
|
236
237
|
+ """
|
|
File without changes
|
|
File without changes
|
|
File without changes
|