Prechádzať zdrojové kódy

localize stored data; click_log.

Stefano Cossu 6 rokov pred
rodič
commit
7d04f73cb5
3 zmenil súbory, kde vykonal 16 pridanie a 4 odobranie
  1. 8 4
      lakesuperior/api/admin.py
  2. 7 0
      lsup-admin
  3. 1 0
      requirements.txt

+ 8 - 4
lakesuperior/api/admin.py

@@ -1,5 +1,6 @@
 import logging
 
+import click_log
 from contextlib import ExitStack
 from shutil import rmtree
 
@@ -35,6 +36,7 @@ def stats():
     return repo_stats
 
 
+@click_log.simple_verbosity_option(logger)
 def dump(
         src, dest, start=('/',), binary_handling='include',
         compact_uris=False):
@@ -91,6 +93,7 @@ def _gather_resources(webroot, start_pts):
             _gather_refs(db, webroot, start)
 
 
+@click_log.simple_verbosity_option(logger)
 def _gather_refs(db, base, path):
     '''
     Get the UID of a resource and its relationships recursively.
@@ -107,6 +110,7 @@ def _gather_refs(db, base, path):
     uri = pfx + path
     # Internal URI of destination.
     iuri = uri.replace(pfx, nsc['fcres'])
+    ibase = base.replace(pfx, nsc['fcres'])
 
     rsp = requests.head(uri)
     rsp.raise_for_status()
@@ -129,7 +133,8 @@ def _gather_refs(db, base, path):
 
     get_req = requests.get(get_uri)
     get_req.raise_for_status()
-    data = get_req.content
+    data = get_req.content.replace(base.encode('utf-8'), ibase.encode('utf-8'))
+    logger.debug('Localized data: {}'.format(data.decode('utf-8')))
     gr = Graph(identifier=iuri).parse(data=data, format='turtle')
 
     # First store the resource, so when we recurse, a resource referring back
@@ -148,12 +153,11 @@ def _gather_refs(db, base, path):
     for pred, obj in gr.predicate_objects():
         if (
                 isinstance(obj, URIRef)
-                and obj.startswith(uri)
+                and obj.startswith(iuri)
                 and pred != nsc['fcrepo'].hasParent):
             with db.begin() as txn:
                 with txn.cursor() as cur:
                     # Avoid ∞
                     if cur.set_key(obj.encode('utf-8')):
-                        #import pdb; pdb.set_trace()
                         continue
-            _gather_refs(db, base, obj.replace(base, ''))
+            _gather_refs(db, base, obj.replace(ibase, ''))

+ 7 - 0
lsup-admin

@@ -1,6 +1,8 @@
 #!/usr/bin/env python
 import click
+import click_log
 import json
+import logging
 import os
 import sys
 
@@ -12,6 +14,9 @@ from lakesuperior.globals import AppGlobals
 from lakesuperior.env import env
 from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
 
+logger = logging.getLogger(__name__)
+click_log.basic_config(logger)
+
 rdfly = env.app_globals.rdfly
 nonrdfly = env.app_globals.nonrdfly
 
@@ -129,6 +134,7 @@ def copy():
     'set to `truncate`, binaries are created as zero-byte files in the proper '
     'folder structure. If set to `skip`, binaries are not exported. Data '
     'folders are not created.')
+@click_log.simple_verbosity_option(logger)
 def dump(src, dest, start, binaries):
     '''
     Dump a repository or parts of it to disk.
@@ -136,6 +142,7 @@ def dump(src, dest, start, binaries):
     Dump an LDP repository to disk. The source repo can be LAKEsuperior or
     another LDP-compatible implementation.
     '''
+    logger.info('Dumping database.')
     return admin_api.dump(src, dest, start, binaries)
 
 

+ 1 - 0
requirements.txt

@@ -5,6 +5,7 @@ Pillow==4.3.0
 PyYAML==3.12
 arrow==0.10.0
 click==6.7
+click-log==0.2.1
 gevent==1.2.2
 gunicorn==19.7.1
 lmdb==0.93