annotate frontends/src/jp/jp @ 393:393b35aa86d2

jp: added --connect option
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2011 00:29:04 +0200
parents c34fd9d6242e
children b2caa2615c4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #! /usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 jp: a SAT command line tool
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 225
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 #consts
191
1438a1337732 About added/updated for Wix & Jp
Goffi <goffi@goffi.org>
parents: 165
diff changeset
23 name = u"jp"
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 225
diff changeset
24 about = name+u""" v%s (c) Jérôme Poisson (aka Goffi) 2009, 2010, 2011
0
goffi@necton2
parents:
diff changeset
25
goffi@necton2
parents:
diff changeset
26 ---
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 225
diff changeset
27 """+name+u""" Copyright (C) 2009, 2010, 2011 Jérôme Poisson (aka Goffi)
0
goffi@necton2
parents:
diff changeset
28 This program comes with ABSOLUTELY NO WARRANTY;
goffi@necton2
parents:
diff changeset
29 This is free software, and you are welcome to redistribute it
goffi@necton2
parents:
diff changeset
30 under certain conditions.
goffi@necton2
parents:
diff changeset
31 ---
goffi@necton2
parents:
diff changeset
32
goffi@necton2
parents:
diff changeset
33 This software is a command line tool for jabber
goffi@necton2
parents:
diff changeset
34 Get the latest version at http://www.goffi.org
goffi@necton2
parents:
diff changeset
35 """
goffi@necton2
parents:
diff changeset
36
goffi@necton2
parents:
diff changeset
37 global pbar_available
goffi@necton2
parents:
diff changeset
38 pbar_available = True #checked before using ProgressBar
goffi@necton2
parents:
diff changeset
39
goffi@necton2
parents:
diff changeset
40 ### logging ###
goffi@necton2
parents:
diff changeset
41 import logging
goffi@necton2
parents:
diff changeset
42 from logging import debug, info, error, warning
goffi@necton2
parents:
diff changeset
43 logging.basicConfig(level=logging.DEBUG,
goffi@necton2
parents:
diff changeset
44 format='%(message)s')
goffi@necton2
parents:
diff changeset
45 ###
goffi@necton2
parents:
diff changeset
46
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
47 import gettext
Goffi <goffi@goffi.org>
parents: 57
diff changeset
48 gettext.install('jp', "i18n", unicode=True)
Goffi <goffi@goffi.org>
parents: 57
diff changeset
49
0
goffi@necton2
parents:
diff changeset
50 import sys
goffi@necton2
parents:
diff changeset
51 import os
goffi@necton2
parents:
diff changeset
52 from os.path import abspath, basename, dirname
goffi@necton2
parents:
diff changeset
53 from optparse import OptionParser
goffi@necton2
parents:
diff changeset
54 import pdb
236
7cf093e138b6 jp: fixed bad sat.tools.jid import
Goffi <goffi@goffi.org>
parents: 228
diff changeset
55 from sat.tools.jid import JID
0
goffi@necton2
parents:
diff changeset
56 import gobject
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
57 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
0
goffi@necton2
parents:
diff changeset
58 import tarfile
goffi@necton2
parents:
diff changeset
59 try:
goffi@necton2
parents:
diff changeset
60 from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
goffi@necton2
parents:
diff changeset
61 except ImportError, e:
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
62 info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
Goffi <goffi@goffi.org>
parents: 57
diff changeset
63 info (_('Progress bar deactivated\n--\n'))
0
goffi@necton2
parents:
diff changeset
64 pbar_available=False
goffi@necton2
parents:
diff changeset
65
goffi@necton2
parents:
diff changeset
66
goffi@necton2
parents:
diff changeset
67
goffi@necton2
parents:
diff changeset
68
goffi@necton2
parents:
diff changeset
69 class JP():
goffi@necton2
parents:
diff changeset
70 def __init__(self):
165
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
71 try:
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
72 self.bridge=DBusBridgeFrontend()
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
73 except BridgeExceptionNoService:
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
74 print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
75 import sys
8a2053de6f8c Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents: 156
diff changeset
76 sys.exit(1)
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
77 self.transfer_id = None
0
goffi@necton2
parents:
diff changeset
78
goffi@necton2
parents:
diff changeset
79 def check_options(self):
goffi@necton2
parents:
diff changeset
80 """Check command line options"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
81 usage=_("""
0
goffi@necton2
parents:
diff changeset
82 %prog [options] [FILE1 FILE2 ...] JID
goffi@necton2
parents:
diff changeset
83 %prog -w [options] [JID1 JID2 ...]
goffi@necton2
parents:
diff changeset
84
goffi@necton2
parents:
diff changeset
85 %prog --help for options list
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
86 """)
191
1438a1337732 About added/updated for Wix & Jp
Goffi <goffi@goffi.org>
parents: 165
diff changeset
87 version = unicode(self.bridge.getVersion())
1438a1337732 About added/updated for Wix & Jp
Goffi <goffi@goffi.org>
parents: 165
diff changeset
88 parser = OptionParser(usage=usage,version=about % version)
0
goffi@necton2
parents:
diff changeset
89
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
90 parser.add_option("-p", "--profile", action="store", type="string", default='@DEFAULT@',
156
a216dfbb0d50 jp: added default value in --profile option's help
Goffi <goffi@goffi.org>
parents: 110
diff changeset
91 help=_("Use PROFILE profile key (default: %default)"))
0
goffi@necton2
parents:
diff changeset
92 parser.add_option("-b", "--bz2", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
93 help=_("Make a bzip2 tarball"))
0
goffi@necton2
parents:
diff changeset
94 parser.add_option("-w", "--wait-file", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
95 help=_("Wait for a file to be sent by a contact"))
0
goffi@necton2
parents:
diff changeset
96 parser.add_option("-m", "--multiple", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
97 help=_("Accept multiple files (you'll have to stop manually)"))
0
goffi@necton2
parents:
diff changeset
98 parser.add_option("-f", "--force", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
99 help=_("Force overwritting of existing files"))
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
100 parser.add_option("-g", "--progress", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
101 help=_("Show progress bar"))
0
goffi@necton2
parents:
diff changeset
102 parser.add_option("-s", "--separate", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
103 help=_("Separate xmpp messages: send one message per line instead of one message alone."))
0
goffi@necton2
parents:
diff changeset
104 parser.add_option("-n", "--new-line", action="store_true", default=False,
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
105 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
106 parser.add_option("--connect", action="store_true", default=False,
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
107 help=_("Connect the profile before doing anything else"))
0
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109 (self.options, args) = parser.parse_args()
goffi@necton2
parents:
diff changeset
110
goffi@necton2
parents:
diff changeset
111 if len(args) < 1 and not self.options.wait_file:
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
112 parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8'))
0
goffi@necton2
parents:
diff changeset
113
goffi@necton2
parents:
diff changeset
114 if self.options.wait_file:
goffi@necton2
parents:
diff changeset
115 #several jid
goffi@necton2
parents:
diff changeset
116 self.dest_jids = args
goffi@necton2
parents:
diff changeset
117 else:
goffi@necton2
parents:
diff changeset
118 #one dest_jid, other args are files
goffi@necton2
parents:
diff changeset
119 self.dest_jid = JID(args[-1])
goffi@necton2
parents:
diff changeset
120 if not self.dest_jid.is_valid:
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
121 error (_("%s is not a valid JID !"), self.dest_jid)
0
goffi@necton2
parents:
diff changeset
122 exit(1)
goffi@necton2
parents:
diff changeset
123 self.files = args[:-1]
goffi@necton2
parents:
diff changeset
124
goffi@necton2
parents:
diff changeset
125 if not pbar_available and self.options.progress:
goffi@necton2
parents:
diff changeset
126 self.options.progress = False
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
127 error (_("Option progress is not available, deactivated."))
0
goffi@necton2
parents:
diff changeset
128
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
129 if self.options.progress or self.options.wait_file or self.options.connect:
0
goffi@necton2
parents:
diff changeset
130 self.start_loop = True #We have to use loop for these options
goffi@necton2
parents:
diff changeset
131 else:
goffi@necton2
parents:
diff changeset
132 self.start_loop = False
goffi@necton2
parents:
diff changeset
133
goffi@necton2
parents:
diff changeset
134
goffi@necton2
parents:
diff changeset
135 return args
goffi@necton2
parents:
diff changeset
136
goffi@necton2
parents:
diff changeset
137 def check_jabber_status(self):
goffi@necton2
parents:
diff changeset
138 """Check that jabber status is allright"""
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
139 def cantConnect():
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
140 error(_(u"Can't connect profile"))
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
141 exit(1)
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
142
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
143
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
144 self.profile = self.bridge.getProfileName(self.options.profile)
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
145 if not self.profile:
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
146 error(_("The profile asked doesn't exist"))
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
147 exit(1)
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
148
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
149 if self.options.connect: #if connection is asked, we connect the profile
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
150 self.bridge.asyncConnect(self.profile, self.connected, cantConnect)
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
151 return
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
152 elif not self.bridge.isConnected(self.profile):
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
153 error(_(u"SàT is not conneted, please connect before using jp"))
0
goffi@necton2
parents:
diff changeset
154 exit(1)
goffi@necton2
parents:
diff changeset
155
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
156 self.connected()
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
157
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
158
0
goffi@necton2
parents:
diff changeset
159
goffi@necton2
parents:
diff changeset
160 def send_stdin(self):
goffi@necton2
parents:
diff changeset
161 """Send incomming data on stdin to jabber contact"""
goffi@necton2
parents:
diff changeset
162 header = "\n" if self.options.new_line else ""
goffi@necton2
parents:
diff changeset
163
goffi@necton2
parents:
diff changeset
164 if self.options.separate: #we send stdin in several messages
goffi@necton2
parents:
diff changeset
165 if header:
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
166 self.bridge.sendMessage(self.dest_jid, header, profile_key=self.profile)
0
goffi@necton2
parents:
diff changeset
167 while (True):
goffi@necton2
parents:
diff changeset
168 line = sys.stdin.readline()
goffi@necton2
parents:
diff changeset
169 if not line:
goffi@necton2
parents:
diff changeset
170 break
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
171 self.bridge.sendMessage(self.dest_jid, line.replace("\n",""), profile_key=self.profile)
0
goffi@necton2
parents:
diff changeset
172 else:
110
cb904fa7de3c jp: profile management (new option: --profile)
Goffi <goffi@goffi.org>
parents: 70
diff changeset
173 self.bridge.sendMessage(self.dest_jid, header + "".join(sys.stdin.readlines()), profile_key=self.profile)
0
goffi@necton2
parents:
diff changeset
174
goffi@necton2
parents:
diff changeset
175 def send_files(self):
goffi@necton2
parents:
diff changeset
176 """Send files to jabber contact"""
goffi@necton2
parents:
diff changeset
177
goffi@necton2
parents:
diff changeset
178 for file in self.files:
goffi@necton2
parents:
diff changeset
179 if not os.path.exists(file):
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
180 error (_("File [%s] doesn't exist !") % file)
0
goffi@necton2
parents:
diff changeset
181 exit(1)
goffi@necton2
parents:
diff changeset
182 if not self.options.bz2 and os.path.isdir(file):
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
183 error (_("[%s] is a dir ! Please send files inside or use compression") % file)
0
goffi@necton2
parents:
diff changeset
184 exit(1)
goffi@necton2
parents:
diff changeset
185
goffi@necton2
parents:
diff changeset
186 if self.options.bz2:
goffi@necton2
parents:
diff changeset
187 tmpfile = (basename(self.files[0]) or basename(dirname(self.files[0])) ) + '.tar.bz2' #FIXME: tmp, need an algorithm to find a good name/path
goffi@necton2
parents:
diff changeset
188 if os.path.exists(tmpfile):
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
189 error (_("tmp file (%s) already exists ! Please remove it"), tmpfile)
0
goffi@necton2
parents:
diff changeset
190 exit(1)
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
191 warning(_("bz2 is an experimental option at an early dev stage, use with caution"))
0
goffi@necton2
parents:
diff changeset
192 #FIXME: check free space, writting perm, tmp dir, filename (watch for OS used)
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
193 info(_("Starting compression, please wait..."))
0
goffi@necton2
parents:
diff changeset
194 sys.stdout.flush()
goffi@necton2
parents:
diff changeset
195 bz2=tarfile.open(tmpfile, "w:bz2")
goffi@necton2
parents:
diff changeset
196 for file in self.files:
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
197 info(_("Adding %s"), file)
0
goffi@necton2
parents:
diff changeset
198 bz2.add(file)
goffi@necton2
parents:
diff changeset
199 bz2.close()
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
200 info(_("OK !"))
0
goffi@necton2
parents:
diff changeset
201 path = abspath(tmpfile)
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
202 self.transfer_id = self.bridge.sendFile(self.dest_jid, path, {}, profile_key=self.profile)
0
goffi@necton2
parents:
diff changeset
203 else:
goffi@necton2
parents:
diff changeset
204 for file in self.files:
goffi@necton2
parents:
diff changeset
205 path = abspath(file)
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
206 self.transfer_id = self.bridge.sendFile(self.dest_jid, path, {}, profile_key=self.profile) #FIXME: show progress only for last transfer_id
0
goffi@necton2
parents:
diff changeset
207
goffi@necton2
parents:
diff changeset
208 #TODO: manage ProgressBar
goffi@necton2
parents:
diff changeset
209
goffi@necton2
parents:
diff changeset
210 def askConfirmation(self, type, id, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
211 """CB used for file transfer, accept files depending on parameters"""
0
goffi@necton2
parents:
diff changeset
212 answer_data={}
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
213 if type == "FILE_TRANSFER":
0
goffi@necton2
parents:
diff changeset
214 if self.dest_jids and not data['from'] in self.dest_jids:
goffi@necton2
parents:
diff changeset
215 return #file is not sent by a filtered jid
goffi@necton2
parents:
diff changeset
216
goffi@necton2
parents:
diff changeset
217 answer_data["dest_path"] = os.getcwd()+'/'+data['filename']
goffi@necton2
parents:
diff changeset
218
goffi@necton2
parents:
diff changeset
219 if self.options.force or not os.path.exists(answer_data["dest_path"]):
goffi@necton2
parents:
diff changeset
220 self.bridge.confirmationAnswer(id, True, answer_data)
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
221 info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']})
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
222 self.transfer_id = id
0
goffi@necton2
parents:
diff changeset
223 else:
goffi@necton2
parents:
diff changeset
224 self.bridge.confirmationAnswer(id, False, answer_data)
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
225 warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']})
0
goffi@necton2
parents:
diff changeset
226
goffi@necton2
parents:
diff changeset
227
goffi@necton2
parents:
diff changeset
228 if not self.options.multiple and not self.options.progress:
goffi@necton2
parents:
diff changeset
229 #we just accept one file
goffi@necton2
parents:
diff changeset
230 self.loop.quit()
goffi@necton2
parents:
diff changeset
231
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 0
diff changeset
232 def actionResult(self, type, id, data):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 0
diff changeset
233 #FIXME
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
234 info (_("FIXME: actionResult not implemented"))
0
goffi@necton2
parents:
diff changeset
235
goffi@necton2
parents:
diff changeset
236 def wait_file(self):
goffi@necton2
parents:
diff changeset
237 """Wait for a file and write it on local dir"""
390
8e87af2e2d1f jp: fixed file reception
Goffi <goffi@goffi.org>
parents: 387
diff changeset
238 self.bridge.register("askConfirmation", self.askConfirmation)
0
goffi@necton2
parents:
diff changeset
239
goffi@necton2
parents:
diff changeset
240 def progressCB(self):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
241 if self.transfer_id:
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 390
diff changeset
242 data = self.bridge.getProgress(self.transfer_id)
0
goffi@necton2
parents:
diff changeset
243 if data:
goffi@necton2
parents:
diff changeset
244 if not data['position']:
goffi@necton2
parents:
diff changeset
245 data['position'] = '0'
goffi@necton2
parents:
diff changeset
246 if not self.pbar:
goffi@necton2
parents:
diff changeset
247 #first answer, we must construct the bar
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
248 self.pbar = ProgressBar(int(data['size']),[_("Progress: "),Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()])
0
goffi@necton2
parents:
diff changeset
249 self.pbar.start()
goffi@necton2
parents:
diff changeset
250
goffi@necton2
parents:
diff changeset
251 self.pbar.update(int(data['position']))
goffi@necton2
parents:
diff changeset
252 elif self.pbar:
goffi@necton2
parents:
diff changeset
253 self.pbar.finish()
goffi@necton2
parents:
diff changeset
254 if not self.options.multiple:
goffi@necton2
parents:
diff changeset
255 self.loop.quit()
goffi@necton2
parents:
diff changeset
256 return False
goffi@necton2
parents:
diff changeset
257
goffi@necton2
parents:
diff changeset
258 return True
goffi@necton2
parents:
diff changeset
259
goffi@necton2
parents:
diff changeset
260 def go(self):
goffi@necton2
parents:
diff changeset
261 self.check_options()
goffi@necton2
parents:
diff changeset
262 self.check_jabber_status()
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
263 if self.start_loop:
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
264 self.loop = gobject.MainLoop()
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
265 try:
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
266 self.loop.run()
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
267 except KeyboardInterrupt:
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
268 info(_("User interruption: good bye"))
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
269
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
270 def connected(self):
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
271 """This is called when the profile is connected"""
0
goffi@necton2
parents:
diff changeset
272 if self.options.wait_file:
goffi@necton2
parents:
diff changeset
273 self.wait_file()
goffi@necton2
parents:
diff changeset
274 else:
goffi@necton2
parents:
diff changeset
275 if not self.files: #we send message only if there are no files to send
goffi@necton2
parents:
diff changeset
276 self.send_stdin()
goffi@necton2
parents:
diff changeset
277 else:
goffi@necton2
parents:
diff changeset
278 self.send_files()
goffi@necton2
parents:
diff changeset
279
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
280 if self.options.progress:
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
281 self.pbar = None
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
282 gobject.timeout_add(10, self.progressCB)
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
283
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
284 if not self.options.progress and not self.options.wait_file:
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
285 self.loop.quit()
0
goffi@necton2
parents:
diff changeset
286
goffi@necton2
parents:
diff changeset
287
goffi@necton2
parents:
diff changeset
288 if __name__ == "__main__":
goffi@necton2
parents:
diff changeset
289 jp = JP()
goffi@necton2
parents:
diff changeset
290 jp.go()