-
Notifications
You must be signed in to change notification settings - Fork 0
/
MulticopyUI.py
103 lines (77 loc) · 2.89 KB
/
MulticopyUI.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
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
98
99
100
101
102
103
'''
Created on Jun 30, 2016
@author: maxr
'''
from tkinter import *
import csv
import xml.etree.ElementTree as ET
from FileIO import FileIO as fIO
import re
class MulticopyUI(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
master.title("Multicopy")
self.pack()
def initUI(self):
pass
def intiMulticopy(self):
fio = fIO()
fio.filePrompt("folder", "Please select folder locations to copy to.\n"
+ "These folder locations will be saved.\n"
+ "When you are done loading in locations, simply\n"
+ "press the cancel button in the file explorer.\n")
try:
tree = ET.parse('filecopylocations.xml')
xroot = tree.getroot()
for locs in xroot.findall('Location'):
xroot.remove(locs)
except:
froot = ET.Element('Directories')
tree = ET.ElementTree(froot)
tree.write('filecopylocations.xml')
tree = ET.parse('filecopylocations.xml')
xroot = tree.getroot()
locnum = 1
fio.folderLocation()
floc = fio.getFolderLocation()
while(floc != ''):
try:
loc = ET.SubElement(xroot, 'Location'.format(locnum))
loc.set('index', '{0}'.format(locnum))
locnum = locnum + 1
loc.text = floc
floc = fio.getFolderLocation()
except:
floc = ''
tree.write('filecopylocations.xml')
ET.dump(xroot)
def getFileNameFromFilePath(self, fpath):
return fpath.split('/').pop()
def multicopy():
try:
tree = ET.parse('filecopylocations.xml')
xroot = tree.getroot()
print "\nWould you like to edit the following copy desitinations?\n"
ET.dump(xroot)
edit = raw_input("\ny=yes : n=no\n")
if edit == 'y':
initMulticopy()
else:
pass
except:
initMulticopy()
tree = ET.parse('filecopylocations.xml')
xroot = tree.getroot()
print "\nPlease select the file you wish to have copied."
try:
fcpyfrom = getFileLocation()
fcpyname = getFileNameFromFilePath(fcpyfrom)
fcpyfrom = open(fcpyfrom, 'r').read()
for loc in xroot.findall('Location'):
f = open(loc.text + '/' + fcpyname, 'w')
f.write(fcpyfrom)
f.close()
print "\nFile was successfully copied!"
except:
print "\nCould not copy file!"
pass