-
Notifications
You must be signed in to change notification settings - Fork 4
/
url_scheme_support.py
81 lines (56 loc) · 1.77 KB
/
url_scheme_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# coding: utf-8
# This file is part of https://github.com/marcus67/gitsynchista
import webbrowser as wb
import urllib
import time
import keychain
import console
import six
import log
import util
import sync_config
if six.PY3:
from urllib.parse import urlencode
from importlib import reload
else:
from urllib import urlencode
reload(log)
reload(util)
reload(sync_config)
PARAM_IGNORE_WAKEUP = 'IGNORE_WAKEUP'
global logger
logger = log.open_logging(__name__)
class UrlSchemeSupport (object):
def __init__(self, app_name):
self.app_name = app_name
self.key = None
def _send_to_app(self, action='', payload={}, x_callback_enabled=False):
# see https://github.com/ahenry91/wc_sync
global logger
if not self.app_name:
logger.warning("Trying to use url scheme without app name. Ignoring request.")
return
logger.debug("_send_to_app: action=%s, x_callback_enabled=%s, playload=%s" % (action, str(x_callback_enabled), str(payload)))
x_callback = 'x-callback-url/' if x_callback_enabled else ''
if self.key:
payload['key'] = self.key
if len(payload) > 0:
payload_string = '/?' + urlencode(payload).replace('+', '%20')
else:
payload_string = ''
fmt = '{app_name}://{x_callback}{action}{payload}'
url = fmt.format(app_name=self.app_name, x_callback=x_callback, action=action, payload=payload_string)
logger.debug("Opening url '%s'" % url)
wb.open(url)
def open_app(self):
self._send_to_app()
time.sleep(2)
def wakeup_webdav_server(self):
pass
def open_repository(self, repository_config=None):
pass
def test():
support = UrlSchemeSupport('working-copy')
support.open_app()
if __name__ == '__main__':
test()