-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCD_Installer.py
More file actions
97 lines (87 loc) · 3.51 KB
/
Copy pathCD_Installer.py
File metadata and controls
97 lines (87 loc) · 3.51 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import os
import tkinter as tk
from tkinter import ttk
class CDUpdate(tk.Tk):
def __init__(self, update_file):
""" Cosmo Dispatch Update/Installer class.
Update the CosmoDispatch application source code
with information provided in predefined format from
inside CD_update.txt file. This is to circumvent
limitations in the ability to send .py extensions
over email.
Noteable Variables
------------------------------
update_file - string
File to load for update. Usually 'CD_update.txt'
"""
# Standard location of local.
location = ''
tk.Tk.__init__(self)
frame = tk.Frame()
frame.pack()
entry = tk.Text(frame, width=50, height=10)
entry.pack()
update_notes = False
try:
with open(update_file, 'r') as u_file:
for line in u_file:
if line[:9] == '[UpNotes]' or update_notes == True:
if line[:9] == '[UpNotes]':
update_notes = True
version = line[9:]
self.title(f'Update # {version}')
continue
elif line[:9] == '[DnNotes]':
update_notes = False
continue
# Display Update Notes.
entry.insert(tk.END, line)
# Locate File Load location. Will return
elif line[:4] == '[FL]':
location = line[4:]
try:
os.remove(location[:-1])
# Catch FileNotFoundError while attempting to delete
# file at location. Continue as this works out.
except FileNotFoundError:
continue
continue # skip the location line
# If location is not empty continue. Otherwise skip
# line assignment.
if location is not '':
self.run_update(location[:-1], line)
# Catch FileNotFoundError while attempting to open CD_update.txt
except FileNotFoundError:
print('File was not located. Verify CD_update.'
'txt was downloaded correctly')
def run_update(self, location, line):
""" Update file at location with line
Write line by line to the specific location listed.
Point of friction as opening and closing the file seems
tedious and may need refractoring.
Noteable Variables
------------------------------
location - string
Location of file to be updated. If not found, create file
then add 'line'.
line - string
String to append to file.
"""
try:
up_file = open(location, 'a')
# Catch FileNotFoundError, if true then Create file first then
# write line.
except FileNotFoundError:
result = location.find('\\')
if not os.path.exists(location[:result]):
print(f'Creating Directory: {location[:result]}')
os.makedirs(location[:result])
# Create file
up_file = open(location, 'w')
finally:
up_file.write(line)
up_file.close()
if __name__ == '__main__':
cdi = CDUpdate('CD_update.txt')
cdi.mainloop()