-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOpsExt.py
More file actions
56 lines (47 loc) · 2.47 KB
/
Copy pathFileOpsExt.py
File metadata and controls
56 lines (47 loc) · 2.47 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
'''
Created on Jun 20, 2017
@author: Coalesce
'''
import os
from pip._vendor.distlib.compat import raw_input
# File handling
filepath = raw_input('Enter a file name to open/create: ')
if(os.path.exists(filepath)):
print("File exists!")
contents = open(filepath, mode = 'r') # 'a','w','r' append, write, read
for i in contents:
print(i)
else:
(dirName, fileName) = os.path.split(filepath)
if not(os.path.exists(dirName)):
os.mkdir(dirName, mode=0o777, dir_fd=None)
print('Dir not found; dir created...')
print("File not found; creating it...")
newFile = open(filepath, mode = 'w') # No explicit file create method - just use open()
newFile.write('''
# Alter PC table to add SWITCH table referential dependency (Foreign Key)
ALTER TABLE PC ADD SWITCH_HOST varchar(25) NOT NULL;
alter table PC modify SWITCH_HOST varchar(25) NULL DEFAULT NULL;
update PC set switch_host = null where 1=1;
alter table PC add constraint fk_switch_host FOREIGN KEY (SWITCH_HOST) REFERENCES SWITCH(HOST);
# Insert data in Switch and update FK in PC table
insert into switch(HOST, IPADDRESS, MACADDRESS, VLAN) values ('DTHSwitch', '172.16.0.58', '01DA.CC22.H901', 1);
update PC set switch_host = 'DTHSwitch' where PCNO = 'PC-1';'''
)
print("File created now!")
newFile.close()
elif(os.path.exists(dirName)) and not (os.path.exists(filepath)):
print('Dir exists; file not found. Creating it...')
newFile = open(filepath, mode = 'w') # No explicit file create method - just use open()
newFile.write('''
# Alter PC table to add SWITCH table referential dependency (Foreign Key)
ALTER TABLE PC ADD SWITCH_HOST varchar(25) NOT NULL;
alter table PC modify SWITCH_HOST varchar(25) NULL DEFAULT NULL;
update PC set switch_host = null where 1=1;
alter table PC add constraint fk_switch_host FOREIGN KEY (SWITCH_HOST) REFERENCES SWITCH(HOST);
# Insert data in Switch and update FK in PC table
insert into switch(HOST, IPADDRESS, MACADDRESS, VLAN) values ('DTHSwitch', '172.16.0.58', '01DA.CC22.H901', 1);
update PC set switch_host = 'DTHSwitch' where PCNO = 'PC-1';'''
)
print("File created now!")
newFile.close()