-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-photos
executable file
·123 lines (106 loc) · 3.09 KB
/
sync-photos
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python
# coding: utf-8
import atexit
import os
import shutil
import subprocess
from ConfigParser import ConfigParser
import wx
conf = ConfigParser()
if os.path.exists('photodownloader.ini'):
conf.read('photodownloader.ini')
else:
conf.read(os.path.expanduser('~/.photodownloader.ini'))
SRC = os.path.expanduser(conf.get('photodownloader', 'src'))
DEST = os.path.expanduser(conf.get('photodownloader', 'dest'))
DELETE = conf.getboolean('photodownloader', 'delete')
AUTOMOUNT = conf.getboolean('photodownloader', 'automount')
MOUNTPOINT = os.path.expanduser(conf.get('photodownloader', 'mountpoint'))
OVERWRITE = conf.getboolean('photodownloader', 'overwrite')
def unmount(*args, **kwargs):
try:
subprocess.check_call(['/bin/umount', MOUNTPOINT])
except Exception, e:
pass
atexit.register(unmount)
#print DEST, DELETE
topframe = None
class MainApp(wx.App):
"""Class Main App."""
def OnInit(self):
"""Init Main App."""
return True
class MainFrame(wx.Frame):
def OnInit(self):
self.filelist = []
self.count = 0
self.working = True
self.mounted = False
self.dlg = wx.ProgressDialog("Kopiranje slik ...",
"Slike se kopirajo, počakaj ... ",
maximum=100,
parent=topframe,
style = wx.PD_APP_MODAL
#| wx.PD_CAN_ABORT
| wx.PD_ELAPSED_TIME
#| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME)
self.dlg.SetPosition(wx.Point(200,200))
self.dlg.Show(True)
self.Bind(wx.EVT_IDLE, self.OnIdle)
return True
def OnIdle(self, event):
global topframe
if self.working and not self.mounted:
print 'Mounting %s' % MOUNTPOINT
try:
subprocess.check_call(['/bin/mount', MOUNTPOINT])
self.mounted = True
except Exception, e:
print e, 2
import traceback
traceback.print_exc()
self.working = False
self.dlg.Hide()
wx.GetApp().ExitMainLoop()
return
else:
self.filelist = [i for i in os.listdir(SRC) if not i.startswith('.')]
if not self.working and self.mounted:
print 'Unmounting %s' % MOUNTPOINT
try:
subprocess.check_call(['/bin/umount', MOUNTPOINT])
self.mounted = False
except Exception, e:
print e, 1
else:
self.dlg.Hide()
wx.GetApp().ExitMainLoop()
return
#print self.GetExitOnFrameDelete()
self.count += 1
if self.count > len(self.filelist):
if self.working:
self.working = False
event.RequestMore()
else:
self.dlg.Hide()
wx.GetApp().ExitMainLoop()
return
if self.count <= len(self.filelist):
fn = self.filelist[self.count-1]
if (not os.path.exists(os.path.join(DEST, fn))) or OVERWRITE:
print 'Copying: %s' % (os.path.join(SRC, fn),)
shutil.copy(os.path.join(SRC, fn), DEST)
if DELETE:
print 'Deleting: %s' % (os.path.join(SRC, fn),)
os.remove(os.path.join(SRC, fn))
self.dlg.Update(self.count*100/len(self.filelist))
self.dlg.SetTitle('%s%% prekopirano' % (self.count*100/len(self.filelist)))
event.RequestMore()
if __name__ == "__main__":
app = MainApp(False)
topframe = MainFrame(None, title="Hello World", size=(300,200))
topframe.OnInit()
app.SetTopWindow(topframe)
app.MainLoop()