-
Notifications
You must be signed in to change notification settings - Fork 0
/
osx_compatibility.py
55 lines (52 loc) · 1.49 KB
/
osx_compatibility.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
# Module
import os
# Where to Look
## Folders
search_folders = [ 'chapters', 'notes' ]
## Files
root_files = [ 'main.tex', 'commands.cmd', 'styles.sty' ]
# Add Header
def modify_file( file_path ):
# Header
osx_header = '% !TEX encoding = UTF-8 Unicode\n'
# Read File
with open(file_path,'r') as in_file:
file_content = in_file.read()
# Modify
if( not( osx_header in file_content ) ):
file_content = osx_header + file_content
# Store File
with open(file_path,'w') as out_file:
out_file.write(file_content)
# Return
return
# Main
if __name__ == '__main__':
# Report
print("\n# --- OSX Compatibility\n")
# Base Files
folder_name = '.'
# Folder Name
print('--> {}'.format( folder_name ))
# Loop over Files
for file_name in root_files:
# File Path
file_path = os.path.join( folder_name, file_name )
# Report
print( file_path )
# Add Header
modify_file( file_path )
# Search Folders
for folder_name in search_folders:
# Folder Name
print('--> {}'.format( folder_name ))
# List files
file_names = [ file_name for file_name in os.listdir(folder_name) if( file_name[-4:] == '.tex' ) ]
# Loop over Files
for file_name in file_names:
# File Path
file_path = os.path.join( folder_name, file_name )
# Report
print( file_path )
# Add Header
modify_file( file_path )