Mercurial > gcp
annotate gcp @ 9:599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
- vfat filename fixing now remove traling spaces
- new param "no_journal" in __filename_fix to avoid writing in journal. Mainly used as a temporary workaround as directory creation is not journalised yet.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Sep 2010 12:26:18 +0800 |
parents | 144cb2669f21 |
children | 00b27fce4677 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 gcp: Goffi's CoPier | |
6 Copyright (C) 2010 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 ### logging ### | |
23 import logging | |
24 from logging import debug, info, error, warning | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
25 logging.basicConfig(level=logging.INFO, |
0 | 26 format='%(message)s') |
27 ### | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
28 |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
29 import gettext |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
30 gettext.install('gcp', "i18n", unicode=True) |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
31 |
0 | 32 import sys |
33 import os,os.path | |
34 from optparse import OptionParser #To be replaced by argparse ASAP | |
1 | 35 import cPickle as pickle |
0 | 36 try: |
37 import gobject | |
38 #DBus | |
39 import dbus, dbus.glib | |
40 import dbus.service | |
41 import dbus.mainloop.glib | |
42 except ImportError,e: | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
43 error(_("Error during import")) |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
44 error(_("Please check dependecies:"),e) |
0 | 45 exit(2) |
46 try: | |
47 from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed | |
48 pbar_available=True | |
49 except ImportError, e: | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
50 info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')) |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
51 info (_('Progress bar deactivated\n--\n')) |
0 | 52 pbar_available=False |
53 | |
54 NAME = "gcp (Goffi's copier)" | |
55 NAME_SHORT = "gcp" | |
56 VERSION = '0.1' | |
57 | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
58 ABOUT = NAME+u" v"+VERSION+u""" (c) Jérôme Poisson (aka Goffi) 2010 |
0 | 59 |
60 --- | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
61 """+NAME+u""" Copyright (C) 2010 Jérôme Poisson |
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
62 """ + _(u"""This program comes with ABSOLUTELY NO WARRANTY; |
0 | 63 This is free software, and you are welcome to redistribute it |
64 under certain conditions. | |
65 --- | |
66 | |
67 This software is an advanced file copier | |
68 Get the latest version at http://www.goffi.org | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
69 """) |
0 | 70 |
71 const_DBUS_INTERFACE = "org.goffi.gcp" | |
3 | 72 const_DBUS_PATH = "/org/goffi/gcp" |
73 const_BUFF_SIZE = 4096 | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
74 const_PRESERVE = set(['mode','ownership','timestamps']) |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
75 const_JOURNAL_PATH = "~/.gcp_journal" |
0 | 76 |
77 | |
78 class DbusObject(dbus.service.Object): | |
79 | |
80 def __init__(self, gcp, bus, path): | |
81 self._gcp = gcp | |
82 dbus.service.Object.__init__(self, bus, path) | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
83 debug(_("Init DbusObject...")) |
0 | 84 self.cb={} |
85 | |
86 @dbus.service.method(const_DBUS_INTERFACE, | |
87 in_signature='', out_signature='s') | |
88 def getVersion(self): | |
89 """Get gcp version | |
90 @return: version as string""" | |
91 return VERSION | |
92 | |
93 @dbus.service.method(const_DBUS_INTERFACE, | |
1 | 94 in_signature='ss', out_signature='bs') |
0 | 95 def addArgs(self, source_path, args): |
96 """Add arguments to gcp as if there were entered on its own command line | |
1 | 97 @param source_path: current working dir to use as base for arguments, as given by os.getcwd() |
98 @param args: serialized (wich pickle) list of strings - without command name -, as given by sys.argv[1:]. | |
99 @return: success (boolean) and error message if any (string)""" | |
100 try: | |
101 args = pickle.loads(str(args)) | |
102 except TypeError, pickle.UnpicklingError: | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
103 return (False, _("INTERNAL ERROR: invalid arguments")) |
0 | 104 return self._gcp.parseArguments(args, source_path) |
105 | |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
106 class Journal(): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
107 def __init__(self, path=const_JOURNAL_PATH): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
108 self.journal_path = os.path.expanduser(path) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
109 self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
110 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
111 def __del__(self): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
112 self.journal_fd.flush() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
113 self.journal_fd.close() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
114 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
115 def startFile(self, source_path): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
116 """Start an entry in the journal""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
117 self.journal_fd.write(source_path+"\n") |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
118 self.journal_fd.flush() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
119 self.success=True |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
120 self.errors=[] |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
121 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
122 def closeFile(self): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
123 """Close the entry in the journal""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
124 if not self.success: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
125 status = "FAILED" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
126 else: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
127 status = "OK" if not self.errors else "PARTIAL" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
128 self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)}) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
129 self.journal_fd.flush() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
130 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
131 def copyFailed(self): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
132 """Must be called when something is wrong with the copy itself""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
133 self.success = False |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
134 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
135 def error(self, name): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
136 """Something went wrong""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
137 self.errors.append(name) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
138 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
139 |
0 | 140 class GCP(): |
141 | |
142 def __init__(self): | |
143 try: | |
144 sessions_bus = dbus.SessionBus() | |
145 db_object = sessions_bus.get_object(const_DBUS_INTERFACE, | |
146 const_DBUS_PATH) | |
147 self.gcp_main = dbus.Interface(db_object, | |
148 dbus_interface=const_DBUS_INTERFACE) | |
149 self._main_instance = False | |
150 | |
151 except dbus.exceptions.DBusException,e: | |
152 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': | |
153 self.launchDbusMainInstance() | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
154 debug (_("gcp launched")) |
0 | 155 self._main_instance = True |
3 | 156 self.buffer_size = const_BUFF_SIZE |
0 | 157 else: |
158 raise e | |
159 | |
160 def launchDbusMainInstance(self): | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
161 debug (_("Init DBus...")) |
0 | 162 session_bus = dbus.SessionBus() |
163 self.dbus_name = dbus.service.BusName(const_DBUS_INTERFACE, session_bus) | |
164 self.dbus_object = DbusObject(self, session_bus, const_DBUS_PATH) | |
165 | |
166 self.copy_list = [] | |
167 self.mounts = self.__getMountPoints() | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
168 self.bytes_total = 0 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
169 self.bytes_copied = 0 |
0 | 170 |
171 def getFsType(self, path): | |
6 | 172 fs = '' |
173 last_mount_point = '' | |
0 | 174 for mount in self.mounts: |
6 | 175 if path.startswith(mount) and len(mount)>=len(last_mount_point): |
0 | 176 fs = self.mounts[mount] |
6 | 177 last_mount_point = mount |
0 | 178 return fs |
179 | |
180 def __getMountPoints(self): | |
181 """Parse /proc/mounts to get currently mounted devices""" | |
182 #TODO: reparse when a new device is added/a device is removed | |
1 | 183 #(check freedesktop mounting signals) |
0 | 184 ret = {} |
185 try: | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
186 with open("/proc/mounts",'rb') as mounts: |
0 | 187 for line in mounts.readlines(): |
188 fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = line.split(' ') | |
189 ret[fs_file] = fs_vfstype | |
190 except: | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
191 error (_("Can't read mounts table")) |
0 | 192 return ret |
193 | |
3 | 194 def __appendToList(self, path, dest_path, options): |
0 | 195 """Add a file to the copy list |
196 @param path: absolute path of file | |
197 @param options: options as return by optparse""" | |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
198 debug (_("Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)") % {"path":path.decode('utf-8','replace'), |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
199 "dest_path":dest_path.decode('utf-8','replace'), |
6 | 200 "fs_type":self.getFsType(dest_path)} ) |
1 | 201 try: |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
202 self.bytes_total+=os.path.getsize(path) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
203 self.copy_list.insert(0,(path, dest_path, options)) |
1 | 204 except OSError,e: |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
205 error(_("Can't copy %(path)s: %(exception)s") % {'path':path.decode('utf-8','replace'), 'exception':e.strerror}) |
0 | 206 |
1 | 207 |
3 | 208 def __appendDirToList(self, dirpath, dest_path, options): |
0 | 209 """Add recursively directory to the copy list |
210 @param path: absolute path of dir | |
211 @param options: options as return by optparse""" | |
3 | 212 #We first check that the dest path exists, and create it if needed |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
213 dest_path = self.__filename_fix(dest_path, options, no_journal=True) |
3 | 214 if not os.path.exists(dest_path): |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
215 debug ("Creating directory %s" % dest_path) |
3 | 216 os.makedirs(dest_path) #TODO: check permissions |
217 #TODO: check that dest_path is an accessible dir, | |
218 # and skip file/write error in log if needed | |
0 | 219 try: |
220 for filename in os.listdir(dirpath): | |
221 filepath = os.path.join(dirpath,filename) | |
222 if os.path.isdir(filepath): | |
3 | 223 full_dest_path = os.path.join(dest_path,filename) |
224 self.__appendDirToList(filepath, full_dest_path, options) | |
0 | 225 else: |
3 | 226 self.__appendToList(filepath, dest_path, options) |
0 | 227 except OSError,e: |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
228 error(_("Can't append %(path)s to copy list: %(exception)s") % {'path':filepath.decode('utf-8','replace'), |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
229 'exception':e.strerror}) |
0 | 230 |
231 def __checkArgs(self, options, source_path, args): | |
232 """Check thats args are files, and add them to copy list""" | |
1 | 233 assert(len (args)>=2) |
234 try: | |
3 | 235 dest_path = os.path.normpath(os.path.join(os.path.expanduser(source_path), args.pop())) |
1 | 236 except OSError,e: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
237 error (_("Invalid dest_path: %s"),e) |
1 | 238 |
0 | 239 for path in args: |
1 | 240 abspath = os.path.normpath(os.path.join(os.path.expanduser(source_path), path)) |
0 | 241 if not os.path.exists(abspath): |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
242 warning(_("The path given in arg doesn't exist or is not accessible: %s") % abspath) |
0 | 243 else: |
244 if os.path.isdir(abspath): | |
3 | 245 full_dest_path = dest_path if os.path.isabs(path) else os.path.normpath(os.path.join(dest_path, path)) |
0 | 246 if not options.recursive: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
247 warning (_('omitting directory "%s"') % abspath) |
0 | 248 else: |
3 | 249 self.__appendDirToList(abspath, full_dest_path, options) |
0 | 250 else: |
3 | 251 self.__appendToList(abspath, dest_path, options) |
0 | 252 |
3 | 253 def __copyNextFile(self): |
254 """Take the last file in the list, and launch the copy using glib io_watch event | |
255 @return: True a file was added, False else""" | |
256 if self.copy_list: | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
257 source_file, dest_path, options = self.copy_list.pop() |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
258 self.journal.startFile(source_file) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
259 source_fd = open(source_file, 'rb') |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
260 filename = os.path.basename(source_file) |
3 | 261 assert(filename) |
6 | 262 dest_file = self.__filename_fix(os.path.join(dest_path,filename),options) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
263 if os.path.exists(dest_file) and not options.force: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
264 warning (_("File [%s] already exists, skipping it !") % dest_file) |
3 | 265 return True |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
266 try: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
267 dest_fd = open(dest_file, 'wb') |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
268 except: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
269 self.journal.copyFailed() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
270 self.journal.error("can't open dest") |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
271 self.journal.closeFile() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
272 source_fd.close() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
273 return True |
3 | 274 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
275 gobject.io_add_watch(source_fd,gobject.IO_IN,self._copyFile, |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
276 (dest_fd, options), priority=gobject.PRIORITY_HIGH) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
277 if not self.progress: |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
278 info(_("COPYING %(source)s ==> %(dest)s") % {"source":source_path.decode('utf-8','replace'), |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
279 "dest":dest_file.decode('utf-8','replace')}) |
3 | 280 return True |
281 else: | |
282 #Nothing left to copy, we quit | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
283 if self.progress: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
284 self.__pbar_finish() |
3 | 285 self.loop.quit() |
286 | |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
287 def __copyFailed(self, reason, source_fd, dest_fd): |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
288 """Write the failure in the journal and close files descriptors""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
289 self.journal.copyFailed() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
290 self.journal.error(reason) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
291 self.journal.closeFile() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
292 source_fd.close() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
293 dest_fd.close() |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
294 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
295 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
296 |
3 | 297 def _copyFile(self, source_fd, condition, data): |
298 """Actually copy the file, callback used with io_add_watch | |
299 @param source_fd: file descriptor of the file to copy | |
300 @param condition: condition which launched the callback (glib.IO_IN) | |
301 @param data: tuple with (destination file descriptor, copying options)""" | |
302 dest_fd,options = data | |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
303 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
304 try: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
305 buff = source_fd.read(self.buffer_size) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
306 except: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
307 self.__copyFailed("can't read source", source_fd, dest_fd) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
308 return False |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
309 |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
310 try: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
311 dest_fd.write(buff) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
312 except: |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
313 self.__copyFailed("can't write to dest", source_fd, dest_fd) |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
314 return False |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
315 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
316 self.bytes_copied += len(buff) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
317 if self.progress: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
318 self.__pbar_update() |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
319 |
3 | 320 if len(buff) != self.buffer_size: |
321 source_fd.close() | |
322 dest_fd.close() | |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
323 self.__post_copy(source_fd.name, dest_fd.name, options) |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
324 self.journal.closeFile() |
3 | 325 return False |
326 return True | |
327 | |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
328 def __filename_fix(self, filename, options, no_journal=False): |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
329 """Fix filenames incompatibilities/mistake according to options |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
330 @param filename: full path to the file |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
331 @param options: options as parsed on command line |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
332 @param no_journal: don't write any entry in journal |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
333 @return: fixed filename""" |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
334 fixed_filename = filename |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
335 |
6 | 336 if self.getFsType(filename) == 'vfat' and options.fs_fix: |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
337 fixed_filename = filename.replace('\\','_')\ |
6 | 338 .replace(':',';')\ |
339 .replace('*','+')\ | |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
340 .replace('?','_')\ |
6 | 341 .replace('"','\'')\ |
342 .replace('<','[')\ | |
343 .replace('>',']')\ | |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
344 .replace('|','!')\ |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
345 .rstrip() #XXX: suffixed spaces cause issues (must check FAT doc for why) |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
346 |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
347 if not fixed_filename: |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
348 fixed_filename = '_' |
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
349 if fixed_filename != filename and not no_journal: |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
350 self.journal.error('filename fixed') |
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
351 return fixed_filename |
6 | 352 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
353 def __post_copy(self, source_file, dest_file, options): |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
354 """Do post copy traitement (mainly managing --preserve option)""" |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
355 st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime = os.stat(source_file) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
356 for preserve in options.preserve: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
357 try: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
358 if preserve == 'mode': |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
359 os.chmod(dest_file, st_mode) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
360 elif preserve == 'ownership': |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
361 os.chown(dest_file, st_uid, st_gid) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
362 elif preserve == 'timestamps': |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
363 os.utime(dest_file, (st_atime, st_mtime)) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
364 except OSError,e: |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
365 self.journal.error("preserve-"+preserve) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
366 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
367 def __pbar_update(self): |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
368 """Update progress bar position, create the bar if it doesn't exist""" |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
369 assert(self.progress) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
370 try: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
371 if self.pbar.maxval != self.bytes_total: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
372 self.pbar.maxval = self.bytes_total |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
373 except AttributeError: |
6 | 374 if not self.bytes_total: |
375 #No progress bar if the files have a null size | |
376 return | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
377 self.pbar = ProgressBar(self.bytes_total,[_("Progress: "),Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()]) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
378 self.pbar.start() |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
379 self.pbar.update(self.bytes_copied) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
380 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
381 def __pbar_finish(self): |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
382 """Mark the progression as finished""" |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
383 assert(self.progress) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
384 try: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
385 self.pbar.finish() |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
386 except AttributeError: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
387 pass |
0 | 388 |
389 def parseArguments(self, full_args=sys.argv[1:], source_path = os.getcwd()): | |
1 | 390 """Parse arguments and add files to queue |
391 @param full_args: list of arguments strings (without program name) | |
392 @param source_path: path from where the arguments come, ad given by os.getcwd() | |
393 @return: a tuple (boolean, message) where the boolean is the success of the arguments | |
394 validation, and message is the error message to print when necessary""" | |
0 | 395 _usage=""" |
396 %prog [options] FILE1 [FILE2 ...] DEST | |
397 | |
398 %prog --help for options list | |
399 """ | |
1 | 400 for idx in range(len(full_args)): |
401 if isinstance(full_args[idx], unicode): | |
402 #We don't want unicode as some filenames can be invalid unicode | |
403 full_args[idx] = full_args[idx].encode('utf-8') | |
404 | |
0 | 405 parser = OptionParser(usage=_usage,version=ABOUT) |
406 | |
407 parser.add_option("-r", "--recursive", action="store_true", default=False, | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
408 help=_("copy directories recursively")) |
0 | 409 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
410 parser.add_option("-f", "--force", action="store_true", default=False, |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
411 help=_("force overwriting of existing files")) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
412 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
413 parser.add_option("--preserve", action="store", default='mode,ownership,timestamps', |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
414 help=_("preserve the specified attributes")) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
415 |
6 | 416 parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True, |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
417 help=_("don't fixe name encoding errors")) #TODO |
6 | 418 |
419 parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True, | |
8 | 420 help=_("don't fixe filesystem name incompatibily")) |
6 | 421 |
3 | 422 parser.add_option("--no-progress", action="store_false", dest="progress", default=True, |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
423 help=_("deactivate progress bar")) |
3 | 424 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
425 parser.add_option("-v", "--verbose", action="store_true", default=False, |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
426 help=_("Show what is currently done")) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
427 |
0 | 428 (options, args) = parser.parse_args(full_args) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
429 #options check |
3 | 430 if options.progress and not pbar_available: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
431 warning (_("Progress bar is not available, deactivating")) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
432 options.progress = self.progress = False |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
433 else: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
434 self.progress = options.progress |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
435 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
436 if options.verbose: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
437 logging.getLogger().setLevel(logging.DEBUG) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
438 |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
439 preserve = set(options.preserve.split(',')) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
440 if not preserve.issubset(const_PRESERVE): |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
441 error (_("Invalide --preserve value\nvalid values are:")) |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
442 for value in const_PRESERVE: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
443 error('- %s' % value) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
444 exit(2) |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
445 else: |
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
446 options.preserve = preserve |
0 | 447 |
4
9feb82bd91aa
--preserve option (same default as for cp) & progress bar are now working.
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
448 #if there is an other instance of gcp, we send options to it |
0 | 449 if not self._main_instance: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
450 info (_("There is already one instance of %s running, pluging to it") % NAME_SHORT) |
1 | 451 #XXX: we have to serialize data as dbus only accept valid unicode, and filenames |
452 # can have invalid unicode. | |
453 return self.gcp_main.addArgs(os.getcwd(),pickle.dumps(full_args)) | |
0 | 454 else: |
1 | 455 if len(args) < 2: |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
456 _error_msg = _("Wrong number of arguments") |
1 | 457 return (False, _error_msg) |
9
599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
458 debug(_("adding args to gcp: %s") % str(args).decode('utf-8','replace')) |
0 | 459 self.__checkArgs(options, source_path, args) |
7
a110d31482f7
Journalisation + some additionnal try/except
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
460 self.journal = Journal() |
3 | 461 gobject.idle_add(self.__copyNextFile) |
1 | 462 return (True,'') |
0 | 463 |
464 def go(self): | |
1 | 465 """Launch main loop""" |
0 | 466 self.loop = gobject.MainLoop() |
467 try: | |
468 self.loop.run() | |
469 except KeyboardInterrupt: | |
5
7edbb0e0d9dd
gettext inclusion & French translation
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
470 info(_("User interruption: good bye")) |
0 | 471 |
472 | |
473 if __name__ == "__main__": | |
474 gcp = GCP() | |
1 | 475 success,message = gcp.parseArguments() |
476 if not success: | |
477 error(message) | |
478 exit(1) | |
0 | 479 if gcp._main_instance: |
480 gcp.go() | |
481 |