Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, remote, path='puller', *args, **kwargs):
super().__init__(path)
remotepath = "file://%s" % os.path.abspath(remote.path)
self.gp = GitPuller(remotepath, 'master', path, *args, **kwargs)
# The default working directory is the directory from which Jupyter
# server is launched, which is not the same as the root notebook
# directory assuming either --notebook-dir= is used from the
# command line or c.NotebookApp.notebook_dir is set in the jupyter
# configuration. This line assures that all repos are cloned
# relative to server_root_dir, so that all repos are always in
# scope after cloning. Sometimes server_root_dir will include
# things like `~` and so the path must be expanded.
repo_dir = os.path.join(os.path.expanduser(self.settings['server_root_dir']),
repo.split('/')[-1])
# We gonna send out event streams!
self.set_header('content-type', 'text/event-stream')
self.set_header('cache-control', 'no-cache')
gp = GitPuller(repo, branch, repo_dir, depth=depth, parent=self.settings['nbapp'])
q = Queue()
def pull():
try:
for line in gp.pull():
q.put_nowait(line)
# Sentinel when we're done
q.put_nowait(None)
except Exception as e:
q.put_nowait(e)
raise e
self.gp_thread = threading.Thread(target=pull)
self.gp_thread.start()
while True:
if urlPath:
path = urlPath
else:
repo_dir = repo.split('/')[-1]
path = os.path.join(repo_dir, subPath)
if app.lower() == 'lab':
path = 'lab/tree/' + path
elif path.lower().endswith('.ipynb'):
path = 'notebooks/' + path
else:
path = 'tree/' + path
self.write(
self.render_template(
'status.html',
repo=repo, branch=branch, path=path, depth=depth, version=__version__
))
self.flush()
def __init__(self, git_url, branch_name, repo_dir, **kwargs):
assert git_url and branch_name
self.git_url = git_url
self.branch_name = branch_name
self.repo_dir = repo_dir
newargs = {k: v for k, v in kwargs.items() if v is not None}
super(GitPuller, self).__init__(**newargs)
def main():
"""
Synchronizes a github repository with a local repository.
"""
logging.basicConfig(
format='[%(asctime)s] %(levelname)s -- %(message)s',
level=logging.DEBUG)
parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
parser.add_argument('git_url', help='Url of the repo to sync')
parser.add_argument('branch_name', default='master', help='Branch of repo to sync', nargs='?')
parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
args = parser.parse_args()
for line in GitPuller(
args.git_url,
args.branch_name,
args.repo_dir
).pull():
print(line)
def load_jupyter_server_extension(nbapp):
web_app = nbapp.web_app
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
handlers = [
(url_path_join(base_url, 'api'), SyncHandler),
(base_url, UIHandler),
(url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler),
(url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler),
(
url_path_join(base_url, 'static', '(.*)'),
StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')}
)
]
web_app.settings['nbapp'] = nbapp
web_app.add_handlers('.*', handlers)
def load_jupyter_server_extension(nbapp):
web_app = nbapp.web_app
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
handlers = [
(url_path_join(base_url, 'api'), SyncHandler),
(base_url, UIHandler),
(url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler),
(url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler),
(
url_path_join(base_url, 'static', '(.*)'),
StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')}
)
]
web_app.settings['nbapp'] = nbapp
web_app.add_handlers('.*', handlers)
def load_jupyter_server_extension(nbapp):
web_app = nbapp.web_app
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
handlers = [
(url_path_join(base_url, 'api'), SyncHandler),
(base_url, UIHandler),
(url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler),
(url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler),
(
url_path_join(base_url, 'static', '(.*)'),
StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')}
)
]
web_app.settings['nbapp'] = nbapp
web_app.add_handlers('.*', handlers)
def load_jupyter_server_extension(nbapp):
web_app = nbapp.web_app
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
handlers = [
(url_path_join(base_url, 'api'), SyncHandler),
(base_url, UIHandler),
(url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler),
(url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler),
(
url_path_join(base_url, 'static', '(.*)'),
StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')}
)
]
web_app.settings['nbapp'] = nbapp
web_app.add_handlers('.*', handlers)