Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_avatar.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
26 from sat.tools import config | 26 from sat.tools import config |
27 import subprocess | 27 import subprocess |
28 | 28 |
29 | 29 |
30 __commands__ = ["Avatar"] | 30 __commands__ = ["Avatar"] |
31 DISPLAY_CMD = ['xv', 'display', 'gwenview', 'showtell'] | 31 DISPLAY_CMD = ["xv", "display", "gwenview", "showtell"] |
32 | 32 |
33 | 33 |
34 class Set(base.CommandBase): | 34 class Set(base.CommandBase): |
35 def __init__(self, host): | 35 def __init__(self, host): |
36 super(Set, self).__init__(host, 'set', use_verbose=True, help=_('set avatar of the profile')) | 36 super(Set, self).__init__( |
37 self.need_loop=True | 37 host, "set", use_verbose=True, help=_("set avatar of the profile") |
38 ) | |
39 self.need_loop = True | |
38 | 40 |
39 def add_parser_options(self): | 41 def add_parser_options(self): |
40 self.parser.add_argument("image_path", type=str, help=_("path to the image to upload")) | 42 self.parser.add_argument( |
43 "image_path", type=str, help=_("path to the image to upload") | |
44 ) | |
41 | 45 |
42 def start(self): | 46 def start(self): |
43 """Send files to jabber contact""" | 47 """Send files to jabber contact""" |
44 path = self.args.image_path | 48 path = self.args.image_path |
45 if not os.path.exists(path): | 49 if not os.path.exists(path): |
46 self.disp(_(u"file [{}] doesn't exist !").format(path), error=True) | 50 self.disp(_(u"file [{}] doesn't exist !").format(path), error=True) |
47 self.host.quit(1) | 51 self.host.quit(1) |
48 path = os.path.abspath(path) | 52 path = os.path.abspath(path) |
49 self.host.bridge.avatarSet(path, self.profile, callback=self._avatarCb, errback=self._avatarEb) | 53 self.host.bridge.avatarSet( |
54 path, self.profile, callback=self._avatarCb, errback=self._avatarEb | |
55 ) | |
50 | 56 |
51 def _avatarCb(self): | 57 def _avatarCb(self): |
52 self.disp(_("avatar has been set"), 1) | 58 self.disp(_("avatar has been set"), 1) |
53 self.host.quit() | 59 self.host.quit() |
54 | 60 |
55 def _avatarEb(self, failure_): | 61 def _avatarEb(self, failure_): |
56 self.disp(_("error while uploading avatar: {msg}").format(msg=failure_), error=True) | 62 self.disp( |
63 _("error while uploading avatar: {msg}").format(msg=failure_), error=True | |
64 ) | |
57 self.host.quit(C.EXIT_ERROR) | 65 self.host.quit(C.EXIT_ERROR) |
58 | 66 |
59 | 67 |
60 class Get(base.CommandBase): | 68 class Get(base.CommandBase): |
61 | |
62 def __init__(self, host): | 69 def __init__(self, host): |
63 super(Get, self).__init__(host, 'get', use_verbose=True, help=_('retrieve avatar of an entity')) | 70 super(Get, self).__init__( |
64 self.need_loop=True | 71 host, "get", use_verbose=True, help=_("retrieve avatar of an entity") |
72 ) | |
73 self.need_loop = True | |
65 | 74 |
66 def add_parser_options(self): | 75 def add_parser_options(self): |
67 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("entity")) | 76 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("entity")) |
68 self.parser.add_argument("-s", "--show", action="store_true", help=_(u"show avatar")) | 77 self.parser.add_argument( |
78 "-s", "--show", action="store_true", help=_(u"show avatar") | |
79 ) | |
69 | 80 |
70 def showImage(self, path): | 81 def showImage(self, path): |
71 sat_conf = config.parseMainConf() | 82 sat_conf = config.parseMainConf() |
72 cmd = config.getConfig(sat_conf, 'jp', 'image_cmd') | 83 cmd = config.getConfig(sat_conf, "jp", "image_cmd") |
73 cmds = [cmd] + DISPLAY_CMD if cmd else DISPLAY_CMD | 84 cmds = [cmd] + DISPLAY_CMD if cmd else DISPLAY_CMD |
74 for cmd in cmds: | 85 for cmd in cmds: |
75 try: | 86 try: |
76 ret = subprocess.call([cmd] + [path]) | 87 ret = subprocess.call([cmd] + [path]) |
77 except OSError: | 88 except OSError: |
81 break | 92 break |
82 else: | 93 else: |
83 # didn't worked with commands, we try our luck with webbrowser | 94 # didn't worked with commands, we try our luck with webbrowser |
84 # in some cases, webbrowser can actually open the associated display program | 95 # in some cases, webbrowser can actually open the associated display program |
85 import webbrowser | 96 import webbrowser |
97 | |
86 webbrowser.open(path) | 98 webbrowser.open(path) |
87 | 99 |
88 def _avatarGetCb(self, avatar_path): | 100 def _avatarGetCb(self, avatar_path): |
89 if not avatar_path: | 101 if not avatar_path: |
90 self.disp(_(u"No avatar found."), 1) | 102 self.disp(_(u"No avatar found."), 1) |
99 def _avatarGetEb(self, failure_): | 111 def _avatarGetEb(self, failure_): |
100 self.disp(_("error while getting avatar: {msg}").format(msg=failure_), error=True) | 112 self.disp(_("error while getting avatar: {msg}").format(msg=failure_), error=True) |
101 self.host.quit(C.EXIT_ERROR) | 113 self.host.quit(C.EXIT_ERROR) |
102 | 114 |
103 def start(self): | 115 def start(self): |
104 self.host.bridge.avatarGet(self.args.jid, False, False, self.profile, callback=self._avatarGetCb, errback=self._avatarGetEb) | 116 self.host.bridge.avatarGet( |
117 self.args.jid, | |
118 False, | |
119 False, | |
120 self.profile, | |
121 callback=self._avatarGetCb, | |
122 errback=self._avatarGetEb, | |
123 ) | |
105 | 124 |
106 | 125 |
107 class Avatar(base.CommandBase): | 126 class Avatar(base.CommandBase): |
108 subcommands = (Set, Get) | 127 subcommands = (Set, Get) |
109 | 128 |
110 def __init__(self, host): | 129 def __init__(self, host): |
111 super(Avatar, self).__init__(host, 'avatar', use_profile=False, help=_('avatar uploading/retrieving')) | 130 super(Avatar, self).__init__( |
131 host, "avatar", use_profile=False, help=_("avatar uploading/retrieving") | |
132 ) |