annotate gcp @ 0:674ce820a4ef

initial commit
author Goffi <goffi@goffi.org>
date Wed, 25 Aug 2010 16:11:34 +0800
parents
children 995487813501
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 gcp: Goffi's CoPier
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2010 Jérôme Poisson (goffi@goffi.org)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
7
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
12
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
17
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
21
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
22 ### logging ###
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import logging
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from logging import debug, info, error, warning
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
25 logging.basicConfig(level=logging.DEBUG,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
26 format='%(message)s')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
27 ###
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import sys
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import os,os.path
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from optparse import OptionParser #To be replaced by argparse ASAP
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
31 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
32 import gobject
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
33 #DBus
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
34 import dbus, dbus.glib
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
35 import dbus.service
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
36 import dbus.mainloop.glib
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except ImportError,e:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38 error("Error during import")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
39 error("Please check dependecies:",e)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
40 exit(2)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
42 from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
43 pbar_available=True
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
44 except ImportError, e:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 info ('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 info ('Progress bar deactivated\n--\n')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 pbar_available=False
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 NAME = "gcp (Goffi's copier)"
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
50 NAME_SHORT = "gcp"
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
51 VERSION = '0.1'
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
52
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
53 ABOUT = NAME+" v"+VERSION+""" (c) Jérôme Poisson (aka Goffi) 2010
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
54
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
55 ---
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
56 """+NAME+""" Copyright (C) 2010 Jérôme Poisson
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
57 This program comes with ABSOLUTELY NO WARRANTY;
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
58 This is free software, and you are welcome to redistribute it
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
59 under certain conditions.
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
60 ---
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
61
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
62 This software is an advanced file copier
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
63 Get the latest version at http://www.goffi.org
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
64 """
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
65
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
66 const_DBUS_INTERFACE = "org.goffi.gcp"
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
67 const_DBUS_PATH = "/org/goffi/gcp"
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
68
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
69
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
70 class DbusObject(dbus.service.Object):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
71
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def __init__(self, gcp, bus, path):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self._gcp = gcp
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
74 dbus.service.Object.__init__(self, bus, path)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
75 debug("Init DbusObject...")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.cb={}
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
77
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @dbus.service.method(const_DBUS_INTERFACE,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
79 in_signature='', out_signature='s')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def getVersion(self):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
81 """Get gcp version
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
82 @return: version as string"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
83 return VERSION
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
84
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
85 @dbus.service.method(const_DBUS_INTERFACE,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
86 in_signature='sas', out_signature='b')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def addArgs(self, source_path, args):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
88 """Add arguments to gcp as if there were entered on its own command line
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
89 @source_path: current working dir to use as base for arguments, as given by os.getcwd()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
90 @args: list of strings - without command name -, as given by sys.argv[1:]"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
91 return self._gcp.parseArguments(args, source_path)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
92
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
93 class GCP():
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
94
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def __init__(self):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
96 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
97 sessions_bus = dbus.SessionBus()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
98 db_object = sessions_bus.get_object(const_DBUS_INTERFACE,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
99 const_DBUS_PATH)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.gcp_main = dbus.Interface(db_object,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
101 dbus_interface=const_DBUS_INTERFACE)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self._main_instance = False
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
103
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
104 except dbus.exceptions.DBusException,e:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
105 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown':
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.launchDbusMainInstance()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 debug ("gcp launched")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self._main_instance = True
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
109 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 raise e
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def launchDbusMainInstance(self):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
113 debug ("Init DBus...")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
114 session_bus = dbus.SessionBus()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.dbus_name = dbus.service.BusName(const_DBUS_INTERFACE, session_bus)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.dbus_object = DbusObject(self, session_bus, const_DBUS_PATH)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
117
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
118 self.copy_list = []
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.mounts = self.__getMountPoints()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
120
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
121 def getFsType(self, path):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
122 fs=''
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
123 for mount in self.mounts:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if path.startswith(mount) and len(self.mounts[mount])>len(fs):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
125 fs = self.mounts[mount]
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
126 return fs
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
127
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def __getMountPoints(self):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
129 """Parse /proc/mounts to get currently mounted devices"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
130 #TODO: reparse when a new device is added/a device is removed
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
131 ret = {}
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
132 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
133 with open("/proc/mounts",'r') as mounts:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
134 for line in mounts.readlines():
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
135 fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = line.split(' ')
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
136 ret[fs_file] = fs_vfstype
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
137 except:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
138 error ("Can't read mounts table")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
139 return ret
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
140
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def __appendToList(self, path, options):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
142 """Add a file to the copy list
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @param path: absolute path of file
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
144 @param options: options as return by optparse"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
145 debug ("Adding to copy list: %s (%s)", path, self.getFsType(path))
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self.copy_list.append((path, options))
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
147
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
148 def __appendDirToList(self, dirpath, options):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
149 """Add recursively directory to the copy list
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
150 @param path: absolute path of dir
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
151 @param options: options as return by optparse"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
152 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
153 for filename in os.listdir(dirpath):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
154 filepath = os.path.join(dirpath,filename)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if os.path.isdir(filepath):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self.__appendDirToList(filepath, options)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
157 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.__appendToList(filepath,options)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
159 except OSError,e:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
160 error("Can't copy %(path)s: %(exception)s" % {'path':dirpath, 'exception':e.strerror})
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
161
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
162 def __checkArgs(self, options, source_path, args):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
163 """Check thats args are files, and add them to copy list"""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
164 for path in args:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
165 abspath = os.path.normpath(os.path.join(source_path, path))
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
166 if not os.path.exists(abspath):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
167 warning("The path given in arg doesn't exist or is not accessible: %s",abspath)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
168 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if os.path.isdir(abspath):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
170 if not options.recursive:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
171 warning ('omitting directory "%s"' % abspath)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
172 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.__appendDirToList(abspath, options)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
174 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
175 self.__appendToList(abspath,options)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
176
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
177
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
178 def parseArguments(self, full_args=sys.argv[1:], source_path = os.getcwd()):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
179 _usage="""
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
180 %prog [options] FILE1 [FILE2 ...] DEST
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
181
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
182 %prog --help for options list
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
183 """
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
184 parser = OptionParser(usage=_usage,version=ABOUT)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
185
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
186 parser.add_option("-r", "--recursive", action="store_true", default=False,
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
187 help="copy directories recursively")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
188
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
189 (options, args) = parser.parse_args(full_args)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
190
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if not self._main_instance:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
192 if args:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
193 info ("There is already one instance of %s running, pluging to it" % NAME_SHORT)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.gcp_main.addArgs(os.getcwd(),full_args)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
195 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
196 error ("There is already one instance of %s running, but we have no argument to send" % NAME_SHORT)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
197 sys.exit(1)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
198 else:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
199 debug("adding args to gcp: %s",args)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
200 self.__checkArgs(options, source_path, args)
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
201
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
202 def go(self):
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
203 self.loop = gobject.MainLoop()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
204 try:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
205 self.loop.run()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
206 except KeyboardInterrupt:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
207 info("User interruption: good bye")
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
208
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
209
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
210 if __name__ == "__main__":
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
211 gcp = GCP()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
212 gcp.parseArguments()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
213 if gcp._main_instance:
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
214 gcp.go()
674ce820a4ef initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
215