-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatechange.py
40 lines (36 loc) · 1.31 KB
/
datechange.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
#! /usr/bin/python
import glob
import re
extensionsToAnalyze = ('*.cbx', '*.bbx')
filesToReplace = []
for selectedExtension in extensionsToAnalyze:
filesToReplace.extend(glob.glob(selectedExtension))
for currentFile in filesToReplace:
print('File ' + currentFile + '...')
inputHandler = open(currentFile, 'r')
for line in inputHandler:
pattern = re.search('\\\\ProvidesFile{(.*)}\\[(.*)\\]', line)
if pattern:
print(' - Current date: ' + pattern.group(2))
inputHandler.close()
newDate = str(raw_input('\nNew date: '))
filesToReplace = []
for selectedExtension in extensionsToAnalyze:
filesToReplace.extend(glob.glob(selectedExtension))
for currentFile in filesToReplace:
print('Processing file ' + currentFile + '...')
inputHandler = open(currentFile, 'r')
newOutput = []
for line in inputHandler:
pattern = re.search('\\\\ProvidesFile{(.*)}\\[(.*)\\]', line)
if pattern:
print(' - from ' + pattern.group(2) + ' to ' + str(newDate))
newOutput.append('\\ProvidesFile{' + pattern.group(1) + '}[' + newDate + ']\n')
else:
newOutput.append(line)
inputHandler.close()
inputHandler = open(currentFile, 'w')
for line in newOutput:
inputHandler.write(line)
inputHandler.close()
print('Ducks.')