Skip to content

Commit ddfbcb6

Browse files
authored
initial of patch_id.py
1 parent 576933c commit ddfbcb6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

patch_id.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Auto Patch id by Invvk (https://github.com/Invvk)
2+
#
3+
# BSD 3-Clause License
4+
#
5+
# Copyright (c) 2021, Invvk
6+
# All rights reserved.
7+
#
8+
# Redistribution and use in source and binary forms, with or without
9+
# modification, are permitted provided that the following conditions are met:
10+
#
11+
# 1. Redistributions of source code must retain the above copyright notice, this
12+
# list of conditions and the following disclaimer.
13+
#
14+
# 2. Redistributions in binary form must reproduce the above copyright notice,
15+
# this list of conditions and the following disclaimer in the documentation
16+
# and/or other materials provided with the distribution.
17+
#
18+
# 3. Neither the name of the copyright holder nor the names of its
19+
# contributors may be used to endorse or promote products derived from
20+
# this software without specific prior written permission.
21+
#
22+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
33+
# Python version 3.8.5
34+
35+
import os
36+
37+
basedir = input('current base directory that contains the patch files: ')
38+
try:
39+
print('biggest patch id (example: 0100-X.patch which means 100 is the biggest or current number):')
40+
currentPoint = int(input('if you want to reset, type 1: '))
41+
except ValueError:
42+
print('Error: patch id can\'t be float (example 1.1 is not acceptable), only integers.')
43+
quit()
44+
45+
if (currentPoint < 1):
46+
print('Error: patch id can\'t be less than 1')
47+
quit()
48+
49+
def format_id(startingPoint):
50+
if startingPoint > 999:
51+
return str(startingPoint)
52+
elif startingPoint > 99:
53+
return "0" + str(startingPoint)
54+
elif startingPoint > 9:
55+
return "00" + str(startingPoint)
56+
return "000" + str(startingPoint)
57+
58+
59+
for file in os.listdir(basedir):
60+
if file.endswith('.patch') and file.startswith('0') and file.__contains__('-'):
61+
newName = format_id(currentPoint) + file.replace(file.split('-')[0], '')
62+
os.rename(f"{basedir}/{file}", f'{basedir}/{newName}')
63+
print(f'renamed {file} to {newName}')
64+
currentPoint += 1

0 commit comments

Comments
 (0)