chname 2.1.3__py3-none-any.whl → 2.1.6__py3-none-any.whl
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/__main__.py +30 -28
- {chname-2.1.3.dist-info → chname-2.1.6.dist-info}/METADATA +13 -7
- chname-2.1.6.dist-info/RECORD +7 -0
- {chname-2.1.3.dist-info → chname-2.1.6.dist-info}/WHEEL +1 -1
- chname-2.1.3.dist-info/RECORD +0 -7
- {chname-2.1.3.dist-info → chname-2.1.6.dist-info}/entry_points.txt +0 -0
- {chname-2.1.3.dist-info → chname-2.1.6.dist-info/licenses}/LICENSE +0 -0
chname/__main__.py
CHANGED
|
@@ -17,7 +17,7 @@ Options:
|
|
|
17
17
|
-f, --fix=<maximum number of digits> Fixes numerical file names
|
|
18
18
|
-h, --help Show this help screen
|
|
19
19
|
-l, --lower Translates the filenames to lowercase
|
|
20
|
-
--merge Merges the files in order
|
|
20
|
+
--merge Merges the files in order specified on command line
|
|
21
21
|
-o, --order Take any input files and fluxes them in numerical order
|
|
22
22
|
-p, --prepend=<prefix> Prefix to be prepended
|
|
23
23
|
--random Randomizes the files
|
|
@@ -38,11 +38,13 @@ import sys
|
|
|
38
38
|
|
|
39
39
|
from docopt import docopt
|
|
40
40
|
|
|
41
|
+
arguments: dict = {}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
|
|
44
|
+
def main() -> None:
|
|
43
45
|
"""Main Method"""
|
|
44
46
|
global arguments
|
|
45
|
-
arguments = docopt(__doc__, version="chname 2.1.
|
|
47
|
+
arguments = docopt(__doc__, version="chname 2.1.6")
|
|
46
48
|
|
|
47
49
|
if arguments["--test"]:
|
|
48
50
|
arguments["--verbose"] = True
|
|
@@ -50,7 +52,7 @@ def main():
|
|
|
50
52
|
flux(arguments["<files>"])
|
|
51
53
|
|
|
52
54
|
|
|
53
|
-
def flux(files):
|
|
55
|
+
def flux(files: list[str]) -> None:
|
|
54
56
|
"""Renames the specified files"""
|
|
55
57
|
|
|
56
58
|
if arguments["--usage"] or not files:
|
|
@@ -75,9 +77,9 @@ def flux(files):
|
|
|
75
77
|
sys.exit(0)
|
|
76
78
|
|
|
77
79
|
|
|
78
|
-
def nameFilesByInputFile(files):
|
|
80
|
+
def nameFilesByInputFile(files) -> None:
|
|
79
81
|
"""Names files by using an input text file"""
|
|
80
|
-
extension = calculateExtension(files)
|
|
82
|
+
extension: str = calculateExtension(files)
|
|
81
83
|
|
|
82
84
|
with open(arguments["--titles"], "r") as fp:
|
|
83
85
|
exportFileNames = [line.strip() for line in fp if line.strip()]
|
|
@@ -89,12 +91,12 @@ def nameFilesByInputFile(files):
|
|
|
89
91
|
)
|
|
90
92
|
)
|
|
91
93
|
|
|
92
|
-
filenameTemplate = (
|
|
94
|
+
filenameTemplate: str = (
|
|
93
95
|
r"{num:02d} - {filename}{extension}" if len(files) < 100 else r"{num:04d} - {filename}{extension}"
|
|
94
96
|
)
|
|
95
|
-
index = 1
|
|
97
|
+
index: int = 1
|
|
96
98
|
for currentFilePath, newFileName in zip(files, exportFileNames):
|
|
97
|
-
newFilePath = os.path.join(
|
|
99
|
+
newFilePath: str = os.path.join(
|
|
98
100
|
os.path.dirname(currentFilePath),
|
|
99
101
|
filenameTemplate.format(num=index, filename=newFileName, extension=extension),
|
|
100
102
|
)
|
|
@@ -102,48 +104,48 @@ def nameFilesByInputFile(files):
|
|
|
102
104
|
index += 1
|
|
103
105
|
|
|
104
106
|
|
|
105
|
-
def orderFiles(files):
|
|
107
|
+
def orderFiles(files) -> None:
|
|
106
108
|
"""Orders the files"""
|
|
107
|
-
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}"
|
|
108
110
|
|
|
109
111
|
for index, currentFilePath in enumerate(sorted(files), 1):
|
|
110
|
-
newFilePath = os.path.join(
|
|
112
|
+
newFilePath: str = os.path.join(
|
|
111
113
|
os.path.dirname(currentFilePath),
|
|
112
114
|
filenameTemplate.format(num=index, filename=os.path.basename(currentFilePath)),
|
|
113
115
|
)
|
|
114
116
|
rename_file(currentFilePath, newFilePath)
|
|
115
117
|
|
|
116
118
|
|
|
117
|
-
def randomizeFiles(files):
|
|
119
|
+
def randomizeFiles(files) -> None:
|
|
118
120
|
"""randomly shuffles a list of files with the same extension"""
|
|
119
121
|
|
|
120
122
|
# determine the extension
|
|
121
|
-
extension = calculateExtension(files)
|
|
123
|
+
extension: str = calculateExtension(files)
|
|
122
124
|
|
|
123
125
|
# do the shuffle
|
|
124
126
|
random.shuffle(files)
|
|
125
127
|
|
|
126
|
-
prefix = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
128
|
+
prefix: str = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
127
129
|
|
|
128
130
|
# rename the files in numeric order
|
|
129
131
|
for index, filename in enumerate(files, 1):
|
|
130
|
-
new_file_name = os.path.join(
|
|
132
|
+
new_file_name: str = os.path.join(
|
|
131
133
|
os.path.dirname(filename),
|
|
132
134
|
"{prefix}_{num:04d}{extension}".format(prefix=prefix, num=index, extension=extension),
|
|
133
135
|
)
|
|
134
136
|
rename_file(filename, new_file_name)
|
|
135
137
|
|
|
136
138
|
|
|
137
|
-
def mergeFiles(files):
|
|
139
|
+
def mergeFiles(files) -> None:
|
|
138
140
|
"""reorders a set of files in order in a target directory"""
|
|
139
141
|
|
|
140
142
|
if not arguments["--directory"]:
|
|
141
143
|
raise SystemExit("--directory must be set")
|
|
142
144
|
|
|
143
145
|
# determine the extension
|
|
144
|
-
extension = calculateExtension(files)
|
|
146
|
+
extension: str = calculateExtension(files)
|
|
145
147
|
|
|
146
|
-
prefix = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
148
|
+
prefix: str = arguments["--prepend"] if arguments["--prepend"] else "file"
|
|
147
149
|
|
|
148
150
|
# rename the files in argument specified order
|
|
149
151
|
for index, filename in enumerate(files, 1):
|
|
@@ -153,23 +155,23 @@ def mergeFiles(files):
|
|
|
153
155
|
rename_file(filename, new_file_name)
|
|
154
156
|
|
|
155
157
|
|
|
156
|
-
def calculateExtension(files):
|
|
158
|
+
def calculateExtension(files) -> str:
|
|
157
159
|
"""determines a single extension"""
|
|
158
|
-
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))
|
|
159
161
|
if len(extensions) > 1:
|
|
160
162
|
raise SystemExit("Only one extension allowed. Found: {}".format(", ".join(extensions)))
|
|
161
163
|
|
|
162
164
|
return extensions.pop()
|
|
163
165
|
|
|
164
166
|
|
|
165
|
-
def performRenameOperation(fileName):
|
|
167
|
+
def performRenameOperation(fileName) -> None:
|
|
166
168
|
"""Performs a renaming operation on the specified filename"""
|
|
167
169
|
if not os.path.exists(fileName):
|
|
168
170
|
if not arguments["--quiet"]:
|
|
169
171
|
print("{} does not exist, skipping.".format(fileName), file=sys.stderr)
|
|
170
172
|
return
|
|
171
173
|
|
|
172
|
-
newFileName = fileName
|
|
174
|
+
newFileName: str = fileName
|
|
173
175
|
|
|
174
176
|
if arguments["--lower"]:
|
|
175
177
|
newFileName = newFileName.lower()
|
|
@@ -195,7 +197,7 @@ def performRenameOperation(fileName):
|
|
|
195
197
|
rename_file(fileName, newFileName)
|
|
196
198
|
|
|
197
199
|
|
|
198
|
-
def rename_file(oldName, newName):
|
|
200
|
+
def rename_file(oldName, newName) -> None:
|
|
199
201
|
"""Performs the actual file rename"""
|
|
200
202
|
if arguments["--verbose"]:
|
|
201
203
|
print("Renaming {} to {}".format(oldName, newName))
|
|
@@ -204,7 +206,7 @@ def rename_file(oldName, newName):
|
|
|
204
206
|
os.rename(oldName, newName)
|
|
205
207
|
|
|
206
208
|
|
|
207
|
-
def substitute(fileName, pattern):
|
|
209
|
+
def substitute(fileName, pattern) -> str:
|
|
208
210
|
"""Performs the pattern substitution"""
|
|
209
211
|
try:
|
|
210
212
|
(old, new) = re.match(r"^(.*)/(.*)$", pattern).groups()
|
|
@@ -213,7 +215,7 @@ def substitute(fileName, pattern):
|
|
|
213
215
|
raise SystemExit("chname: Illegal substitute pattern. Pattern must be old/new")
|
|
214
216
|
|
|
215
217
|
|
|
216
|
-
def fixNumbers(fileName, delimiter, numberLength):
|
|
218
|
+
def fixNumbers(fileName, delimiter, numberLength) -> str:
|
|
217
219
|
"""Fixes the numeric part of a filename"""
|
|
218
220
|
if delimiter not in fileName:
|
|
219
221
|
return fileName
|
|
@@ -221,7 +223,7 @@ def fixNumbers(fileName, delimiter, numberLength):
|
|
|
221
223
|
(base, extension) = os.path.splitext(fileName)
|
|
222
224
|
(prefix, number) = base.split(delimiter, 2)
|
|
223
225
|
|
|
224
|
-
sequenceValue = number
|
|
226
|
+
sequenceValue: str = number
|
|
225
227
|
|
|
226
228
|
for i in range(len(number), int(numberLength)):
|
|
227
229
|
sequenceValue = "0" + sequenceValue
|
|
@@ -229,7 +231,7 @@ def fixNumbers(fileName, delimiter, numberLength):
|
|
|
229
231
|
return prefix + delimiter + sequenceValue + extension
|
|
230
232
|
|
|
231
233
|
|
|
232
|
-
def usage():
|
|
234
|
+
def usage() -> None:
|
|
233
235
|
print(
|
|
234
236
|
__doc__
|
|
235
237
|
+ """
|
|
@@ -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
|
|
@@ -28,7 +34,7 @@ Options:
|
|
|
28
34
|
-f, --fix=<maximum number of digits> Fixes numerical file names
|
|
29
35
|
-h, --help Show this help screen
|
|
30
36
|
-l, --lower Translates the filenames to lowercase
|
|
31
|
-
--merge Merges the files in order
|
|
37
|
+
--merge Merges the files in order specified on command line
|
|
32
38
|
-o, --order Take any input files and renames them in numerical order
|
|
33
39
|
-p, --prepend=<prefix> Prefix to be prepended
|
|
34
40
|
--random Randomizes the files
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
chname/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
chname/__main__.py,sha256=9sMa8VtOMt1I-xfnx2ujklgOgfdyKQCQOsQlv9yFvX0,8652
|
|
3
|
+
chname-2.1.6.dist-info/METADATA,sha256=NJs9sQoPtVAEZD1pWUEfMXU4e4oLQ0kIhU3vCYVkP3Y,2517
|
|
4
|
+
chname-2.1.6.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
5
|
+
chname-2.1.6.dist-info/entry_points.txt,sha256=l8ek6yn-OaGAak7ye2y-kPeGb6YMnYcwwHfQ1ygX6sk,47
|
|
6
|
+
chname-2.1.6.dist-info/licenses/LICENSE,sha256=wT_mfbxynx42y5DZ0-Kuf_pie3PaQPeK5nXUL8_V1WQ,1073
|
|
7
|
+
chname-2.1.6.dist-info/RECORD,,
|
chname-2.1.3.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
chname/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
chname/__main__.py,sha256=XgO4ct66Ml2sCVGB3CMIgFkQcmPEDnqBHyUDE8vNuAQ,8450
|
|
3
|
-
chname-2.1.3.dist-info/LICENSE,sha256=wT_mfbxynx42y5DZ0-Kuf_pie3PaQPeK5nXUL8_V1WQ,1073
|
|
4
|
-
chname-2.1.3.dist-info/METADATA,sha256=kyEYLgWR4Ya9-M5KrEQf3irZ5f6B3MIBB61I5k3Jcoo,2220
|
|
5
|
-
chname-2.1.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
6
|
-
chname-2.1.3.dist-info/entry_points.txt,sha256=l8ek6yn-OaGAak7ye2y-kPeGb6YMnYcwwHfQ1ygX6sk,47
|
|
7
|
-
chname-2.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|