def testStoreConfig(self): init_repository(self.local, False) conf = QuitConfiguration(configfile=self.localConfigFile) self.assertEqual(conf.getRepoPath(), self.local) self.assertEqual(conf.getOrigin(), 'git://github.com/aksw/QuitStore.git') allFiles = conf.getgraphsfromdir() self.assertEqual( sorted(allFiles), sorted(['config.ttl', 'example1.nq', 'example2.nt', 'example3.nq']))
def initialize(args): """Build all needed objects. Returns: A dictionary containing the store object and git repo object. """ 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: {}".format(args.logfile)) except FileNotFoundError: logger.error("Logfile not found: {}".format(args.logfile)) sys.exit('Exiting quit') except PermissionError: logger.error("Can not create logfile: {}".format(args.logfile)) sys.exit('Exiting quit') if args.disableversioning: logger.info('Versioning: disabled') v = False else: logger.info('Versioning: enabled') v = True try: config = QuitConfiguration( versioning=v, configfile=args.configfile, targetdir=args.targetdir, repository=args.repourl, configmode=args.configmode, ) except InvalidConfigurationError as e: logger.error(e) sys.exit('Exiting quit') gitrepo = GitRepo( path=config.getRepoPath(), origin=config.getOrigin() ) try: gitrepo = GitRepo( path=config.getRepoPath(), origin=config.getOrigin() ) except Exception as e: raise InvalidConfigurationError(e) if args.garbagecollection: try: with subprocess.Popen( ["git", "config", "gc.auto"], stdout=subprocess.PIPE, cwd=config.getRepoPath() ) as gcAutoThresholdProcess: stdout, stderr = gcAutoThresholdProcess.communicate() gcAutoThreshold = stdout.decode("UTF-8").strip() if not gcAutoThreshold: gcAutoThreshold = 256 subprocess.Popen( ["git", "config", "gc.auto", str(gcAutoThreshold)], cwd=config.getRepoPath() ) logger.info("Set default gc.auto threshold {}".format(gcAutoThreshold)) gitrepo.gc = True logger.info( "Garbage Collection is enabled with gc.auto threshold {}".format( gcAutoThreshold ) ) except Exception as e: # Disable garbage collection for the rest of the run because it # is likely that git is not available logger.info('Git garbage collection could not be configured and was disabled') logger.debug(e) # since repo is handled, we can add graphs to config config.initgraphconfig() store = initializeMemoryStore(config) # Save file objects per file filereferences = {} for file in config.getfiles(): graphs = config.getgraphuriforfile(file) content = [] for graph in graphs: content += store.getgraphcontent(graph) fileobject = FileReference(join(config.getRepoPath(), file)) # TODO: Quick Fix, add sorting to FileReference fileobject.setcontent(sorted(content)) filereferences[file] = fileobject logger.info('QuitStore successfully running.') logger.info('Known graphs: ' + str(config.getgraphs())) logger.info('Known files: ' + str(config.getfiles())) logger.debug('Path of Gitrepo: ' + config.getRepoPath()) logger.debug('Config mode: ' + str(config.getConfigMode())) logger.debug('All RDF files found in Gitepo:' + str(config.getgraphsfromdir())) updateConfig(store, config, gitrepo, filereferences)