Skip to content

Commit d2c1113

Browse files
committed
First version
1 parent 4c905c7 commit d2c1113

14 files changed

+12354
-0
lines changed

.gitignore

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
turtlegit.egg-info
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyTest
71+
72+
.pytest_cache
73+
.pydevproject
74+
.project
75+
76+
# PyBuilder
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# pyenv
83+
.python-version
84+
85+
# celery beat schedule file
86+
celerybeat-schedule
87+
88+
# SageMath parsed files
89+
*.sage.py
90+
91+
# Environments
92+
.env
93+
.venv
94+
env/
95+
venv/
96+
ENV/
97+
env.bak/
98+
venv.bak/
99+
100+
# Spyder project settings
101+
.spyderproject
102+
.spyproject
103+
104+
# Rope project settings
105+
.ropeproject
106+
107+
# mkdocs documentation
108+
/site
109+
110+
# mypy
111+
.mypy_cache/

settings.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[DEFAULT]
2+
;Workspace = c:/some/path
3+
Domain = http://localhost:5000/
4+
AutoAdd = True
5+
AutoCommit = True
6+
7+
[LOGGING]
8+
Level = DEBUG

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[aliases]
2+
test=pytest

setup.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='turtlegit',
5+
packages=['turtlegit'],
6+
include_package_data=True,
7+
install_requires=[
8+
'flask',
9+
'rdflib'
10+
],
11+
setup_requires=[
12+
'pytest-runner',
13+
],
14+
tests_require=[
15+
'pytest',
16+
],
17+
)

turtlegit/__init__.py

Whitespace-only changes.

turtlegit/cmdgit.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from subprocess import Popen, PIPE
2+
import logging as log
3+
import re
4+
5+
def add(fileName, repoDir):
6+
log.debug('Adding '+fileName+' to '+repoDir)
7+
cmd = 'git add ' + fileName
8+
if not pipeSuccess(cmd, repoDir):
9+
log.warn('FAILED to add '+fileName+' to '+repoDir)
10+
11+
def commit(commitMessage, repoDir):
12+
log.debug('Committing all to '+repoDir)
13+
cmd = 'git commit -am "%s"'%commitMessage
14+
if not pipeSuccess(cmd, repoDir):
15+
log.warn('FAILED to commit all '+repoDir)
16+
17+
def push(repoDir):
18+
cmd = 'git push '
19+
if not pipeSuccess(cmd, repoDir):
20+
log.warn('FAILED to push '+repoDir)
21+
22+
def status(repoDir):
23+
cmd = 'git status '
24+
return pipeSuccess(cmd, repoDir)
25+
26+
def init(repoDir):
27+
cmd ='git init '
28+
return pipeSuccess(cmd, repoDir)
29+
30+
def rmAll(repoDir):
31+
cmd = 'git rm *'
32+
return pipeSuccess(cmd,repoDir)
33+
34+
def pipeSuccess(cmd, repoDir):
35+
try:
36+
pipe = Popen(cmd, shell=True, cwd=repoDir,stdout = PIPE,stderr = PIPE)
37+
(output,error)= pipe.communicate()
38+
if 'fatal' in error.decode('ascii'):
39+
log.warn(error)
40+
log.info(output)
41+
except (OSError, NotADirectoryError) as exception:
42+
log.warn('Exception: ' + str(exception))
43+
else:
44+
return pipe.wait() == 0
45+
46+
def size(repoDir):
47+
cmd = 'git count-objects -v -H '
48+
p = Popen(cmd, shell=True, cwd=repoDir, stdout=PIPE)
49+
output = p.communicate()[0].decode('ascii')
50+
size_pack = re.search("(?<=size-pack: )\d+", output).group()
51+
return size_pack
52+
53+
def modified(repoDir):
54+
cmd = 'git ls-files -m '
55+
p = Popen(cmd, shell=True, cwd=repoDir, stdout=PIPE)
56+
output = p.communicate()[0].decode('ascii')
57+
return output
58+
59+
def lsfiles(repoDir):
60+
cmd = 'git ls-files '
61+
p = Popen(cmd, shell=True, cwd=repoDir, stdout=PIPE)
62+
output = p.communicate()[0].decode('ascii')
63+
return output.splitlines()
64+
65+
def loglast(repoDir):
66+
cmd = 'git log -p -1 '
67+
p = Popen(cmd, shell=True, cwd=repoDir, stdout=PIPE)
68+
output = p.communicate()[0].decode('utf-8')
69+
return output
70+
71+
def setHome():
72+
cmd = 'set HOME='
73+
p = Popen(cmd, shell=True, stdout=PIPE)
74+
output = p.communicate()[0].decode('utf-8')
75+
return output
76+
77+
def getHome():
78+
cmd = 'set HOME'
79+
p = Popen(cmd, shell=True, stdout=PIPE)
80+
output = p.communicate()[0].decode('utf-8')
81+
return output
82+
83+
84+

turtlegit/default_settings.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from os import path
2+
3+
class Config(object):
4+
DOMAIN = 'http://localhost/'
5+
AUTOADD = True
6+
AUTOCOMMIT = True
7+
ROOT_DIR = path.dirname(path.dirname(__file__)).replace('\\','/')
8+
9+
class Logging(object):
10+
LEVEL = 'DEBUG'

turtlegit/filegraph.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from rdflib.graph import Graph
2+
from rdflib.namespace import Namespace
3+
from otsrdflib import OrderedTurtleSerializer
4+
from urllib.parse import quote_plus, unquote_plus
5+
import io
6+
import logging as log
7+
import posixpath
8+
from os import path
9+
10+
class FileGraph:
11+
12+
g = None
13+
repopath = None
14+
reponame = None
15+
domain = None
16+
filename = None
17+
filepath = None
18+
19+
def __init__(self, iri, domain, repopath, reponame):
20+
self.iri = iri
21+
self.domain = domain
22+
self.repopath = repopath
23+
self.reponame = reponame
24+
self.g = Graph()
25+
26+
log.info("IRI: "+self.iri)
27+
log.info("DOMAIN: "+domain)
28+
if iri.startswith(domain):
29+
self.filename = iri.rsplit('/', 1)[-1]
30+
if not self.filename.endswith('.ttl'):
31+
self.filename += '.ttl'
32+
else:
33+
self.filename = quote_plus(iri.replace(domain+self.reponame,''))+".ttl"
34+
35+
self.filepath = posixpath.join(repopath,self.filename)
36+
37+
def doExists(self):
38+
return path.isfile(self.filepath)
39+
40+
def parseFile(self, f):
41+
self.g.parse(f, format='turtle')
42+
43+
def parseString(self, modelString):
44+
f = io.StringIO(modelString)
45+
self.g.parse(f, format='turtle')
46+
47+
def parsePath(self):
48+
self.g.parse(self.filepath, format='turtle')
49+
50+
def serialize(self):
51+
serializer = OrderedTurtleSerializer(self.g)
52+
with open(self.filepath, 'wb') as fp:
53+
serializer.serialize(fp)

0 commit comments

Comments
 (0)