Skip to content

Commit

Permalink
Merge pull request #1 from zzhangjii/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
zzhangjii authored Jul 13, 2017
2 parents 95a5e71 + 1044d81 commit ac23dd8
Show file tree
Hide file tree
Showing 11 changed files with 1,985 additions and 1 deletion.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# jupyterlab-git
A Git extension for JupyterLab
pre-alpha version


JLG


## Prerequisites

* JupyterLab

## Installation for git-plugin

```bash
jupyter labextension install jupyterlab-git
```

## Development

For a development install (requires npm version 4 or later), do the following in the repository directory:

```bash
npm install
jupyter labextension link .
```

To rebuild the package and the JupyterLab app:

```bash
npm run build
jupyter lab build
```

##Installation and activation for jupyterlab_git python handler package

```bash
pip install jupyterlab_git
jupyter serverextension enable --py jupyterlab_git
jupyter nbextension install --py jupyterlab_git
```

To enable this extension:

```bash
jupyter nbextension enable --py jupyterlab_git

```
20 changes: 20 additions & 0 deletions jupyterlab_git/jupyterlab_git/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from jupyterlab_git.handlers import setup_handlers
from jupyterlab_git.git_class import Git
# Jupyter Extension points
def _jupyter_server_extension_paths():
return [{
'module': 'jupyterlab_git',
}]

def _jupyter_nbextension_paths():
return [{
"section": "notebook",
"dest": "jupyterlab_git",
"src": "static",
"require": "jupyterlab_git/one"
}]

def load_jupyter_server_extension(nbapp):
git = Git()
nbapp.web_app.settings['git'] = git
setup_handlers(nbapp.web_app)
72 changes: 72 additions & 0 deletions jupyterlab_git/jupyterlab_git/git_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

import os
import json
import socket
import time
import subprocess as sp
import psutil
from tornado import web
import subprocess
import errno
import io
import shutil
import stat
import sys
import warnings
import mimetypes
import nbformat


from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler



class Git:
def status(self, current_path):
my_output = subprocess.check_output(["git", "status", "--porcelain"], cwd = os.getcwd()+'/'+current_path)
print(os.getcwd())
print(current_path)
return my_output

def showtoplevel(self, current_path):
my_output = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd = os.getcwd()+'/'+current_path)
print(os.getcwd())
print(current_path)
return my_output

def add(self, filename, top_repo_path):
my_output = subprocess.check_output(["git", "add", filename], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def add_all(self, top_repo_path):
my_output = subprocess.check_output(["git", "add", "-u"], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def reset(self, filename, top_repo_path):
my_output = subprocess.check_output(["git", "reset", filename], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def reset_all(self, top_repo_path):
my_output = subprocess.check_output(["git", "reset"], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def checkout(self, filename, top_repo_path):
my_output = subprocess.check_output(["git", "checkout", "--", filename], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def checkout_all(self, top_repo_path):
my_output = subprocess.check_output(["git", "checkout", "--", "."], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

def commit(self, commit_msg, top_repo_path):
my_output = subprocess.check_output(["git", "commit", "-m", commit_msg], cwd = top_repo_path)
print("Hi there! post extensions!!")
return my_output

110 changes: 110 additions & 0 deletions jupyterlab_git/jupyterlab_git/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

import os
import json
import socket
import time
import subprocess as sp
import psutil
from tornado import web
import subprocess


from notebook.utils import url_path_join
from notebook.base.handlers import APIHandler



class Git_handler(APIHandler):
@property
def git(self):
return self.settings['git']

class Git_showtoplevel_handler(Git_handler):
def post(self):
my_data = json.loads(self.request.body)
current_path = my_data["current_path"]
my_output = (self.git.showtoplevel(current_path)).decode('utf-8').strip('\n')
print(my_output)
self.finish(json.dumps(my_output))

class Git_status_handler(Git_handler):
def get(self):
#my_data = json.loads(self.request.body)

print("Hi there! get extensions!!")

def post(self):
result = []
my_data = json.loads(self.request.body)
current_path = my_data["current_path"]
my_output = self.git.status(current_path)
line_array = my_output.decode('utf-8').splitlines()
for line in line_array:
result.append({'x':line[0],'y':line[1],'to':line[3:],'from':None})
self.finish(json.dumps(result))



class Git_add_handler(Git_handler):
def post(self):
my_data = json.loads(self.request.body)
top_repo_path = my_data["top_repo_path"]
if(my_data["add_all"]):
my_output = self.git.add_all(top_repo_path)
else:
filename = my_data["filename"]
print(filename)
print(top_repo_path)
my_output = self.git.add(filename, top_repo_path)
self.finish(my_output)
print("Hi there! git add handler!!")

class Git_reset_handler(Git_handler):
def post(self):
my_data = json.loads(self.request.body)
top_repo_path = my_data["top_repo_path"]
if(my_data["reset_all"]):
my_output = self.git.reset_all(top_repo_path)
else:
filename = my_data["filename"]

print(filename)
print(top_repo_path)

my_output = self.git.reset(filename, top_repo_path)
self.finish(my_output)
print("Hi there! git reset handler!!")

class Git_checkout_handler(Git_handler):
def post(self):
my_data = json.loads(self.request.body)
top_repo_path = my_data["top_repo_path"]
if(my_data["checkout_all"]):
my_output = self.git.checkout_all(top_repo_path)
else:
filename = my_data["filename"]

print(filename)
print(top_repo_path)

my_output = self.git.checkout(filename, top_repo_path)
self.finish(my_output)
print("Hi there! git checkout handler!!")

class Git_commit_handler(Git_handler):
def post(self):
my_data = json.loads(self.request.body)
top_repo_path = my_data["top_repo_path"]
commit_msg = my_data["commit_msg"]
my_output = self.git.commit(commit_msg, top_repo_path)
self.finish(my_output)
print("Hi there! git commit handler!!")


def setup_handlers(web_app):
web_app.add_handlers('.*', [('/git/showtoplevel', Git_showtoplevel_handler)])
web_app.add_handlers('.*', [('/git/add', Git_add_handler)])
web_app.add_handlers('.*', [('/git/status', Git_status_handler)])
web_app.add_handlers('.*', [('/git/reset', Git_reset_handler)])
web_app.add_handlers('.*', [('/git/checkout', Git_checkout_handler)])
web_app.add_handlers('.*', [('/git/commit', Git_commit_handler)])
40 changes: 40 additions & 0 deletions jupyterlab_git/jupyterlab_git/static/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
define(['jquery', 'base/js/utils'], function ($, utils) {

var $ = require('jquery');
var Jupyter = require('base/js/namespace');
var utils = require('base/js/utils');

//var ajax = $.ajax;

var base_url = utils.get_body_data('baseUrl');

function open_rsession() {

var rsp_url = base_url + '/git_handler';
console.log("Let's Go and test it!!!!!!!!!!00000");

var settings = {
type: "POST",
data: {},
dataType: "json",
success: function(data) {
console.log("Data drop to server Success");
},
error : utils.log_ajax_error,
}
console.log("Let's Go and test it!!!!!!!!!!111111");
$.ajax(rsp_url, settings);


console.log("Let's Go and test it!!!!!!!!!!2223334");
}

function load() {
console.log("Let's Go and test it!!!!!!!!!!");

}

return {
load_ipython_extension: load
};
});
11 changes: 11 additions & 0 deletions jupyterlab_git/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import setuptools

setuptools.setup(
name='jupyterlab_git',
version='0.1.0',
packages=setuptools.find_packages(),
install_requires=[
'notebook',
],
package_data={'jupyterlab_git': ['static/*']},
)
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

{
"name": "jupyterlab-git",
"version": "0.1.0",
"description": "JLG",
"author": "interns",
"main": "lib/index.js",
"keywords": [
"jupyter",
"jupyterlab"
],
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"prepublish": "npm run build"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/*.css"
],
"jupyterlab": {
"extension": true
},
"dependencies": {
"@jupyterlab/application": "^0.7.0",
"@jupyterlab/apputils": "0.7.0",
"@jupyterlab/console": "^0.7.0",
"@jupyterlab/coreutils": "^0.7.0",
"@jupyterlab/docmanager": "^0.7.0",
"@jupyterlab/docregistry": "^0.7.0",
"@jupyterlab/filebrowser": "^0.7.0",
"@jupyterlab/launcher": "^0.7.0",
"@jupyterlab/launcher-extension": "^0.7.1",
"@jupyterlab/services": "^0.46.0",
"@phosphor/algorithm": "^1.1.1",
"@phosphor/application": "^1.3.0",
"@phosphor/commands": "^1.2.1",
"@phosphor/coreutils": "^1.1.1",
"@phosphor/disposable": "^1.1.1",
"@phosphor/signaling": "^1.2.1",
"@phosphor/widgets": "^1.3.0",
"core-js": "^2.4.1",
"es6-promise": "^4.1.0",
"jquery": "^2.2.0"
},
"devDependencies": {
"rimraf": "^2.6.1",
"typescript": "~2.2.0"
}
}
Loading

0 comments on commit ac23dd8

Please sign in to comment.