-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehelper.py
More file actions
31 lines (27 loc) · 879 Bytes
/
filehelper.py
File metadata and controls
31 lines (27 loc) · 879 Bytes
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
class FileHelper:
def __init__(self, filename):
self.filename = filename
self.header = []
self.body = []
self.footer = []
self.indent_level = 0
self.minified = False
def insert_header(self, content):
""" Insert the Content in the Header section of the file. """
self.header.append(content + "\n")
def insert_content(self, content):
""" Insert the Content in the Body section of the file. """
if not self.minified:
self.body.append(("\t" * self.indent_level) + content + "\n")
else:
self.body.append(content)
def insert_footer(self, content):
""" Insert the Content in the Footer section of the file. """
self.footer.append(content + "\n")
def write_data_to_file(self):
""" Write all the Data stored to File. """
f = open(self.filename, 'w')
f.writelines(self.header)
f.writelines(self.body)
f.writelines(self.footer)
f.close()