Mercurial > libervia-backend
annotate frontends/src/jp/cmd_file.py @ 853:c2f6ada7858f
core (sqlite): automatic database update:
- new Updater class check database consistency (by calculating a hash on the .schema), and updates base if necessary
- database now has a version (1 for current, 0 will be for 0.3's database), for each change this version will be increased
- creation statements and update statements are in the form of dict of dict with tuples. There is a help text at the top of the module to explain how it works
- if we are on a development version, the updater try to update the database automaticaly (without deleting table or columns). The Updater.generateUpdateData method can be used to ease the creation of update data (i.e. the dictionary at the top, see the one for the key 1 for an example).
- if there is an inconsistency, an exception is raised, and a message indicate the SQL statements that should fix the situation.
- well... this is rather complicated, a KISS method would maybe have been better. The future will say if we need to simplify it :-/
- new DatabaseError exception
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 23 Feb 2014 23:30:32 +0100 |
parents | 300b4de701a6 |
children | 069ad98b360d |
rev | line source |
---|---|
815 | 1 #! /usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # jp: a SAT command line tool | |
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
814 | 20 from logging import debug, info, error, warning |
0 | 21 |
814 | 22 import base |
23 import sys | |
24 import os | |
25 import os.path | |
26 import tarfile | |
771 | 27 from sat.core.i18n import _ |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
28 |
817 | 29 __commands__ = ["File"] |
0 | 30 |
817 | 31 class Send(base.CommandBase): |
32 def __init__(self, host): | |
33 super(Send, self).__init__(host, 'send', use_progress=True, help=_('Send a file to a contact')) | |
0 | 34 |
817 | 35 def add_parser_options(self): |
36 self.parser.add_argument("files", type=str, nargs = '+', help=_("A list of file")) | |
37 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("The destination jid")) | |
38 self.parser.add_argument("-b", "--bz2", action="store_true", help=_("Make a bzip2 tarball")) | |
0 | 39 |
817 | 40 def connected(self): |
41 """Send files to jabber contact""" | |
42 self.need_loop=True | |
43 super(Send, self).connected() | |
44 self.send_files() | |
401
b2caa2615c4c
jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
45 |
0 | 46 def send_files(self): |
47 | |
817 | 48 for file_ in self.args.files: |
49 if not os.path.exists(file_): | |
50 error (_(u"file [%s] doesn't exist !") % file_) | |
51 self.host.quit(1) | |
52 if not self.args.bz2 and os.path.isdir(file_): | |
53 error (_("[%s] is a dir ! Please send files inside or use compression") % file_) | |
54 self.host.quit(1) | |
55 | |
56 full_dest_jid = self.host.get_full_jid(self.args.jid) | |
57 | |
58 if self.args.bz2: | |
59 tmpfile = (os.path.basename(self.args.files[0]) or os.path.basename(os.path.dirname(self.args.files[0])) ) + '.tar.bz2' #FIXME: tmp, need an algorithm to find a good name/path | |
0 | 60 if os.path.exists(tmpfile): |
817 | 61 error (_("tmp file_ (%s) already exists ! Please remove it"), tmpfile) |
0 | 62 exit(1) |
70 | 63 warning(_("bz2 is an experimental option at an early dev stage, use with caution")) |
0 | 64 #FIXME: check free space, writting perm, tmp dir, filename (watch for OS used) |
817 | 65 print _(u"Starting compression, please wait...") |
0 | 66 sys.stdout.flush() |
817 | 67 bz2 = tarfile.open(tmpfile, "w:bz2") |
68 for file_ in self.args.files: | |
69 print _(u"Adding %s") % file_ | |
70 bz2.add(file_) | |
0 | 71 bz2.close() |
817 | 72 print _(u"Done !") |
73 path = os.path.abspath(tmpfile) | |
74 self.progress_id = self.host.bridge.sendFile(full_dest_jid, path, {}, self.profile) | |
0 | 75 else: |
817 | 76 for file_ in self.args.files: |
77 path = os.path.abspath(file_) | |
78 self.progress_id = self.host.bridge.sendFile(full_dest_jid, path, {}, self.profile) #FIXME: show progress only for last progress_id | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
79 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
80 |
817 | 81 class Receive(base.CommandAnswering): |
82 confirm_type = "FILE_TRANSFER" | |
0 | 83 |
817 | 84 def __init__(self, host): |
85 super(Receive, self).__init__(host, 'recv', use_progress=True, help=_('Wait for a file to be sent by a contact')) | |
0 | 86 |
817 | 87 @property |
88 def dest_jids(self): | |
89 return self.args.jids | |
393 | 90 |
817 | 91 def add_parser_options(self): |
92 self.parser.add_argument("jids", type=base.unicode_decoder, nargs="*", help=_('Jids accepted (none means "accept everything")')) | |
93 self.parser.add_argument("-m", "--multiple", action="store_true", help=_("Accept multiple files (you'll have to stop manually)")) | |
94 self.parser.add_argument("-f", "--force", action="store_true", help=_("Force overwritting of existing files")) | |
0 | 95 |
96 | |
817 | 97 def ask(self, data, confirm_id): |
98 answer_data = {} | |
99 answer_data["dest_path"] = os.path.join(os.getcwd(), data['filename']) | |
100 | |
101 if self.args.force or not os.path.exists(answer_data["dest_path"]): | |
102 self.host.bridge.confirmationAnswer(confirm_id, True, answer_data, self.profile) | |
103 info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']}) | |
104 self.progress_id = confirm_id | |
105 else: | |
106 self.host.bridge.confirmationAnswer(confirm_id, False, answer_data, self.profile) | |
107 warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']}) | |
108 if not self.args.multiple: | |
109 self.host.quit() | |
110 | |
111 if not self.args.multiple and not self.args.progress: | |
814 | 112 #we just accept one file |
817 | 113 self.host.quit() |
114 | |
115 def run(self): | |
116 super(Receive, self).run() | |
117 if self.args.multiple: | |
118 self.host.quit_on_progress_end = False | |
119 | |
120 | |
121 class File(base.CommandBase): | |
122 subcommands = (Send, Receive) | |
123 | |
124 def __init__(self, host): | |
125 super(File, self).__init__(host, 'file', use_profile=False, help=_('File sending/receiving')) |