Commit c286e381 authored by Jakob Hollenstein's avatar Jakob Hollenstein
Browse files

sharelatex git-bridge fixes by simon haller.

parent 088eb210
...@@ -24,6 +24,7 @@ setup_requires = ...@@ -24,6 +24,7 @@ setup_requires =
wheel>=0.31.0 wheel>=0.31.0
install_requires = install_requires =
socketIO-client==0.5.7.4 socketIO-client==0.5.7.4
websocket-client==0.59.0
click~= 7.0 click~= 7.0
GitPython~=2.1.13 GitPython~=2.1.13
filetype~=1.0.5 filetype~=1.0.5
......
...@@ -171,7 +171,12 @@ def get_csrf_Token(html_text): ...@@ -171,7 +171,12 @@ def get_csrf_Token(html_text):
the csrf token (str) if found in html_text or None if not the csrf token (str) if found in html_text or None if not
""" """
if "csrfToken" in html_text: if "csrfToken" in html_text:
return re.search('(?<=csrfToken = ").{36}', html_text).group(0) ## works with Sharelatex <2.3
#return re.search('(?<=csrfToken = ").{36}', html_text).group(0)
## works with Sharelatex 2.6.1
#return re.search('(?<=csrfToken" content=").{36}', html_text).group(0)
## works with Sharelatex 2.X
return re.findall(r'<input name="_csrf" type="hidden" value="(?P<token>.*?)">', html_text)[0]
else: else:
return None return None
...@@ -221,10 +226,12 @@ class SyncClient: ...@@ -221,10 +226,12 @@ class SyncClient:
"password": password, "password": password,
"_csrf": self.csrf, "_csrf": self.csrf,
} }
logger.debug(" try login") logger.debug("try to login")
_r = self._post(login_url, data=self.login_data, verify=self.verify) _r = self._post(login_url, data=self.login_data, verify=self.verify)
_r.raise_for_status() _r.raise_for_status()
check_error(_r.json()) # Post returns on a successful login a 'text/html' not a 'json'
if 'json' in _r.headers.get('Content-Type'):
check_error(_r.json())
else: else:
# try to find CAS form # try to find CAS form
from lxml import html from lxml import html
...@@ -259,6 +266,7 @@ class SyncClient: ...@@ -259,6 +266,7 @@ class SyncClient:
self.login_data.pop("password") self.login_data.pop("password")
self.sharelatex_sid = _r.cookies["sharelatex.sid"] self.sharelatex_sid = _r.cookies["sharelatex.sid"]
# logger.debug(self.sharelatex_sid)
def get_project_data(self, project_id): def get_project_data(self, project_id):
"""Get the project hierarchy and some metadata. """Get the project hierarchy and some metadata.
......
...@@ -20,6 +20,13 @@ logger.addHandler(handler) ...@@ -20,6 +20,13 @@ logger.addHandler(handler)
set_logger(logger) set_logger(logger)
def remote_headless():
"""Exit if we do not have access to the keyring"""
print("Keyring is not available - on remote or headless machines try:")
print("source $HOME/.dbus/session-bus/*")
os._exit(os.EX_UNAVAILABLE)
def set_log_level(verbose=0): def set_log_level(verbose=0):
"""set log level from interger value""" """set log level from interger value"""
LOG_LEVELS = (logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG) LOG_LEVELS = (logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG)
...@@ -42,16 +49,28 @@ class Config: ...@@ -42,16 +49,28 @@ class Config:
def __init__(self, repo): def __init__(self, repo):
self.repo = repo self.repo = repo
self.keyring = keyring.get_keyring() try:
self.keyring = keyring.get_keyring()
except:
remote_headless()
def get_password(self, service, username): def get_password(self, service, username):
return self.keyring.get_password(service, username) try:
return self.keyring.get_password(service, username)
except:
remote_headless()
def set_password(self, service, username, password): def set_password(self, service, username, password):
self.keyring.set_password(service, username, password) try:
self.keyring.set_password(service, username, password)
except:
remote_headless()
def delete_password(self, service, username): def delete_password(self, service, username):
self.keyring.delete_password(service, username) try:
self.keyring.delete_password(service, username)
except:
remote_headless()
def set_value(self, section, key, value, config_level="repository"): def set_value(self, section, key, value, config_level="repository"):
"""Set a config value in a specific section. """Set a config value in a specific section.
...@@ -523,6 +542,9 @@ def clone( ...@@ -523,6 +542,9 @@ def clone(
directory = Path(directory, project_id) directory = Path(directory, project_id)
else: else:
directory = Path(directory) directory = Path(directory)
if os.path.isdir(directory):
print("Exiting: Local Directory Exists")
os._exit(os.EX_CANTCREAT)
directory.mkdir(parents=True, exist_ok=False) directory.mkdir(parents=True, exist_ok=False)
repo = get_clean_repo(path=directory) repo = get_clean_repo(path=directory)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment