Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_utils.py @ 1367:f71a0fc26886
merged branch frontends_multi_profiles
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Mar 2015 10:52:28 +0100 |
parents | faa1129559b8 |
children | 069ad98b360d |
comparison
equal
deleted
inserted
replaced
1295:1e3b1f9ad6e2 | 1367:f71a0fc26886 |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 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/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat_frontends.tools.jid import JID | 20 from sat.core.i18n import _ |
21 from os.path import exists, splitext | 21 from os.path import exists, splitext |
22 from sat_frontends.quick_frontend.constants import Const | 22 from optparse import OptionParser |
23 | |
24 def escapePrivate(ori_jid): | |
25 """Escape a private jid""" | |
26 return JID(Const.PRIVATE_PREFIX + ori_jid.bare + '@' + ori_jid.resource) | |
27 | |
28 def unescapePrivate(escaped_jid): | |
29 if not escaped_jid.startswith(Const.PRIVATE_PREFIX): | |
30 return escaped_jid | |
31 escaped_split = tuple(escaped_jid[len(Const.PRIVATE_PREFIX):].split('@')) | |
32 assert(len(escaped_split) == 3) | |
33 return JID("%s@%s/%s" % escaped_split) | |
34 | 23 |
35 def getNewPath(path): | 24 def getNewPath(path): |
36 """ Check if path exists, and find a non existant path if needed """ | 25 """ Check if path exists, and find a non existant path if needed """ |
37 idx = 2 | 26 idx = 2 |
38 if not exists(path): | 27 if not exists(path): |
42 new_path = "%s_%d%s" % (root, idx, ext) | 31 new_path = "%s_%d%s" % (root, idx, ext) |
43 if not exists(new_path): | 32 if not exists(new_path): |
44 return new_path | 33 return new_path |
45 idx+=1 | 34 idx+=1 |
46 | 35 |
36 def check_options(): | |
37 """Check command line options""" | |
38 usage = _(""" | |
39 %prog [options] | |
40 | |
41 %prog --help for options list | |
42 """) | |
43 parser = OptionParser(usage=usage) # TODO: use argparse | |
44 | |
45 parser.add_option("-p", "--profile", help=_("Select the profile to use")) | |
46 | |
47 (options, args) = parser.parse_args() | |
48 if options.profile: | |
49 options.profile = options.profile.decode('utf-8') | |
50 return options | |
51 |