Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions quit/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
from rdflib.util import guess_format
from urllib.parse import quote, urlparse

conflogger = logging.getLogger('conf.quit')
# create file handler which logs even debug messages
fh = logging.FileHandler('quit.log')
fh.setLevel(logging.DEBUG)
conflogger.addHandler(fh)
logger = logging.getLogger('quit.conf')


class QuitConfiguration:
Expand All @@ -32,6 +28,7 @@ def __init__(
If the config file is missing, it will be generated after analyzing the
file structure.
"""
logger = logging.getLogger('quit.conf.QuitConfiguration')
self.configchanged = False
self.sysconf = Graph()
self.graphconf = None
Expand Down Expand Up @@ -116,7 +113,7 @@ def __initgraphsfromdir(self, repodir):
try:
tmpgraph.parse(source=absfile, format=format)
except:
conflogger.warning('Could not parse graphfile ' + absfile + ' skipped.')
logger.warning('Could not parse graphfile ' + absfile + ' skipped.')
continue

namedgraphs = tmpgraph.contexts()
Expand All @@ -130,15 +127,15 @@ def __initgraphsfromdir(self, repodir):
if len(founduris) == 1:
self.addgraph(file=file, graphuri=graphuri, format=format)
elif len(founduris) > 1:
conflogger.warning('No named graph found. ' + absfile + ' skipped.')
logger.warning('No named graph found. ' + absfile + ' skipped.')
elif len(founduris) < 1:
conflogger.warning('More than one named graphs found. Can\'t decide. ' + absfile + ' skipped.')
logger.warning('More than one named graphs found. Can\'t decide. ' + absfile + ' skipped.')

elif format == 'nt':
if graphuri:
self.addgraph(file=file, graphuri=graphuri, format=format)
else:
conflogger.warning('No .graph file found. ' + absfile + ' skipped.')
logger.warning('No .graph file found. ' + absfile + ' skipped.')

self.__setgraphsfromconf()

Expand Down
55 changes: 27 additions & 28 deletions quit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from rdflib import ConjunctiveGraph, Graph, URIRef, BNode
from subprocess import Popen

corelogger = logging.getLogger('core.quit')

logger = logging.getLogger('quit.core')

class FileReference:
"""A class that manages n-quad files.
Expand All @@ -34,8 +33,8 @@ def __init__(self, filelocation, versioning=True):
Raises:
ValueError: If no file at the filelocation, or in the given directory + filelocation.
"""
self.logger = logging.getLogger('file_reference_core.quit')
self.logger.debug('Create an instance of FileReference')
logger = logging.getLogger('quit.core.FileReference')
logger.debug('Create an instance of FileReference')
self.content = None
self.path = abspath(filelocation)
self.modified = False
Expand Down Expand Up @@ -69,13 +68,13 @@ def getgraphfromfile(self):

try:
graph.parse(self.path, format='nquads', publicID='http://localhost:5000/')
self.logger.debug('Success: File', self.path, 'parsed')
logger.debug('Success: File', self.path, 'parsed')
# quadstring = graph.serialize(format="nquads").decode('UTF-8')
# quadlist = quadstring.splitlines()
# self.__setcontent(quadlist)
except:
# Given file contains non valid rdf data
# self.logger.debug('Error: File', self.path, 'not parsed')
# logger.debug('Error: File', self.path, 'not parsed')
# self.__setcontent([[None][None][None][None]])
pass

Expand All @@ -102,13 +101,13 @@ def savefile(self):
"""Save the file."""
f = open(self.path, "w")

self.logger.debug('Saving file:', self.path)
logger.debug('Saving file:', self.path)
content = self.__getcontent()
for line in content:
f.write(line + '\n')
f.close

self.logger.debug('File saved')
logger.debug('File saved')

def sortcontent(self):
"""Order file content."""
Expand Down Expand Up @@ -164,8 +163,8 @@ class MemoryStore:

def __init__(self):
"""Initialize a new MemoryStore instance."""
self.logger = logging.getLogger('memory_store.core.quit')
self.logger.debug('Create an instance of MemoryStore')
logger = logging.getLogger('quit.core.MemoryStore')
logger.debug('Create an instance of MemoryStore')
self.store = ConjunctiveGraph(identifier='default')

return
Expand Down Expand Up @@ -239,8 +238,8 @@ def addfile(self, filename, serialization):
try:
self.store.parse(source=filename, format=serialization)
except:
self.logger.debug('Could not import', filename, '.')
self.logger.debug('Make sure the file exists and contains data in', serialization)
logger.debug('Could not import', filename, '.')
logger.debug('Make sure the file exists and contains data in', serialization)
pass

return
Expand Down Expand Up @@ -321,8 +320,8 @@ def __init__(self, path, origin=None):
Args:
path: A string containing the path to the repository.
"""
self.logger = logging.getLogger('git_repo.core.quit')
self.logger.debug('GitRepo, init, Create an instance of GitStore')
logger = logging.getLogger('quit.core.GitRepo')
logger.debug('GitRepo, init, Create an instance of GitStore')
self.path = path

if not exists(path):
Expand Down Expand Up @@ -385,7 +384,7 @@ def addfile(self, filename):
index.add(filename)
index.write()
except:
self.logger.debug('GitRepo, addfile, Couldn\'t add file', filename)
logger.debug('GitRepo, addfile, Couldn\'t add file', filename)

def addRemote(self, name, url):
"""Add a remote.
Expand All @@ -396,15 +395,15 @@ def addRemote(self, name, url):
"""
try:
self.repo.remotes.create(name, url)
self.logger.debug('GitRepo, addRemote, successfully added remote', name, url)
logger.debug('GitRepo, addRemote, successfully added remote', name, url)
except:
self.logger.debug('GitRepo, addRemote, could not add remote', name, url)
logger.debug('GitRepo, addRemote, could not add remote', name, url)

try:
self.repo.remotes.set_push_url(name, url)
self.repo.remotes.set_url(name, url)
except:
self.logger.debug('GitRepo, addRemote, could not set urls', name, url)
logger.debug('GitRepo, addRemote, could not set urls', name, url)

def checkout(self, commitid):
"""Checkout a commit by a commit id.
Expand All @@ -416,9 +415,9 @@ def checkout(self, commitid):
commit = self.repo.revparse_single(commitid)
self.repo.set_head(commit.oid)
self.repo.reset(commit.oid, GIT_RESET_HARD)
self.logger.debug('GitRepo, checkout, Checked out commit:', commitid)
logger.debug('GitRepo, checkout, Checked out commit:', commitid)
except:
self.logger.debug('GitRepo, checkout, Commit-ID (' + commitid + ') does not exist')
logger.debug('GitRepo, checkout, Commit-ID (' + commitid + ') does not exist')

def commit(self, message=None):
"""Commit staged files.
Expand Down Expand Up @@ -458,9 +457,9 @@ def commit(self, message=None):
tree,
[self.repo.head.get_object().hex]
)
self.logger.debug('GitRepo, commit, Updates commited')
logger.debug('GitRepo, commit, Updates commited')
except:
self.logger.debug('GitRepo, commit, Nothing to commit')
logger.debug('GitRepo, commit, Nothing to commit')

def commitexists(self, commitid):
"""Check if a commit id is part of the repository history.
Expand Down Expand Up @@ -492,7 +491,7 @@ def garbagecollection(self):
"""
self.gcProcess = Popen(["git", "gc", "--auto", "--quiet"])
except Exception as e:
self.logger.debug('Git garbage collection failed to spawn', e)
logger.debug('Git garbage collection failed to spawn', e)
return

def getpath(self):
Expand Down Expand Up @@ -573,7 +572,7 @@ def pull(self, remote='origin', branch='master'):
try:
self.repo.remotes[remote].fetch()
except:
self.logger.debug('GitRepo, pull, No remote', remote)
logger.debug('GitRepo, pull, No remote', remote)

ref = 'refs/remotes/' + remote + '/' + branch
remoteid = self.repo.lookup_reference(ref).target
Expand Down Expand Up @@ -602,7 +601,7 @@ def pull(self, remote='origin', branch='master'):
[self.repo.head.target, remoteid])
self.repo.state_cleanup()
else:
self.logger.debug('GitRepo, pull, Unknown merge analysis result')
logger.debug('GitRepo, pull, Unknown merge analysis result')

def push(self, remote='origin', branch='master'):
"""Push if possible.
Expand All @@ -616,13 +615,13 @@ def push(self, remote='origin', branch='master'):
try:
remo = self.repo.remotes[remote]
except:
self.logger.debug('GitRepo, push, Remote:', remote, 'does not exist')
logger.debug('GitRepo, push, Remote:', remote, 'does not exist')
return

try:
remo.push(ref, callbacks=self.callback)
except:
self.logger.debug('GitRepo, push, Can not push to', remote, 'with ref', ref)
logger.debug('GitRepo, push, Can not push to', remote, 'with ref', ref)

def getRemotes(self):
remotes = {}
Expand Down Expand Up @@ -663,7 +662,7 @@ def setCallback(self, origin):
try:
credentials = Keypair(username, pubkey, privkey, passphrase)
except:
self.logger.debug('GitRepo, setcallback: Something went wrong with Keypair')
logger.debug('GitRepo, setcallback: Something went wrong with Keypair')
return

return RemoteCallbacks(credentials=credentials)
47 changes: 35 additions & 12 deletions quit/quit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,14 @@
werkzeugLogger = logging.getLogger('werkzeug')
werkzeugLogger.setLevel(logging.INFO)

logger = logging.getLogger('core')
logger = logging.getLogger('quit')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('quit.log')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)


def __savefiles():
"""Update the files after a update query was executed on the store."""
Expand Down Expand Up @@ -180,11 +173,37 @@ def initialize(args):
"""
gc = False

if args.verbose:
ch.setLevel(logging.INFO)
logger.addHandler(ch)
logger.debug('Loglevel: INFO')

if args.verboseverbose:
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
logger.debug('Loglevel: DEBUG')

# add the handlers to the logger

if args.logfile:
try:
fh = logging.FileHandler(args.logfile)
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.debug('Logfile: '+ args.logfile)
except FileNotFoundError:
logger.error('Logfile not found: ' + args.logfile)
sys.exit('Exiting quit')
except PermissionError:
logger.error('Can not create logfile: ' + args.logfile)
sys.exit('Exiting quit')

if args.disableversioning:
logger.info('Versioning is disabled')
logger.info('Versioning: disabled')
v = False
else:
logger.info('Versioning is enabled')
logger.info('Versioning: enabled')
v = True

if args.garbagecollection:
Expand Down Expand Up @@ -652,11 +671,15 @@ def parseArgs(args):
"repoconfig" - Use the configuration of the git repository for graphs settings.
"graphfiles" - Use *.graph-files for each RDF file to get the named graph URI."""
confighelp = """Path of config file (turtle). Defaults to ./config.ttl."""
loghelp = """Path to the log file."""

parser = argparse.ArgumentParser()
parser.add_argument('-nv', '--disableversioning', action='store_true')
parser.add_argument('-gc', '--garbagecollection', action='store_true')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-vv', '--verboseverbose', action='store_true')
parser.add_argument('-c', '--configfile', type=str, default='config.ttl', help=confighelp)
parser.add_argument('-l', '--logfile', type=str, help=loghelp)
parser.add_argument('-r', '--repourl', type=str, help='A link/URI to a remote repository.')
parser.add_argument('-t', '--targetdir', type=str, help='The directory of the local store repository.')
parser.add_argument('-cm', '--configmode', type=str, choices=[
Expand Down
Loading