mirror of https://github.com/papermerge/mglib
refactoring the concepts of endpoint... I thing even better name would be DocumentPath, PagePath
parent
13afcedbe7
commit
47a67be4dd
|
@ -6,6 +6,9 @@ from botocore.errorfactory import ClientError
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
AUX_DIR_DOCS = "docs"
|
||||||
|
AUX_DIR_RESULTS = "results"
|
||||||
|
|
||||||
|
|
||||||
def get_keyname(s3_url):
|
def get_keyname(s3_url):
|
||||||
"""
|
"""
|
||||||
|
@ -115,8 +118,8 @@ class Endpoint:
|
||||||
|
|
||||||
class DocumentEp:
|
class DocumentEp:
|
||||||
"""
|
"""
|
||||||
Document Endpoint:
|
Document Endpoint path:
|
||||||
<schema>://<media_root>/<aux_dir>/<user_id>/<doc_id>/<version>/<file_name>
|
/<aux_dir>/<user_id>/<doc_id>/<version>/<file_name>
|
||||||
|
|
||||||
If version = 0, it is not included in Endpoint.
|
If version = 0, it is not included in Endpoint.
|
||||||
Document's version is incremented everytime pdftk operation runs on it
|
Document's version is incremented everytime pdftk operation runs on it
|
||||||
|
@ -125,16 +128,12 @@ class DocumentEp:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
remote_endpoint,
|
|
||||||
local_endpoint,
|
|
||||||
user_id,
|
user_id,
|
||||||
document_id,
|
document_id,
|
||||||
file_name,
|
file_name,
|
||||||
aux_dir="docs",
|
aux_dir=AUX_DIR_DOCS,
|
||||||
version=0
|
version=0
|
||||||
):
|
):
|
||||||
self.remote_endpoint = remote_endpoint
|
|
||||||
self.local_endpoint = local_endpoint
|
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.document_id = document_id
|
self.document_id = document_id
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
|
@ -157,11 +156,26 @@ class DocumentEp:
|
||||||
return full_path
|
return full_path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dirname(self):
|
def dirname_docs(self):
|
||||||
root_dir = f"{self.local_endpoint.dirname}"
|
_path = (
|
||||||
|
f"{AUX_DIR_DOCS}/user_{self.user_id}/"
|
||||||
|
f"document_{self.document_id}/"
|
||||||
|
)
|
||||||
|
|
||||||
|
return _path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dirname_results(self):
|
||||||
|
_path = (
|
||||||
|
f"{AUX_DIR_RESULTS}/user_{self.user_id}/"
|
||||||
|
f"document_{self.document_id}/"
|
||||||
|
)
|
||||||
|
|
||||||
|
return _path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dirname(self):
|
||||||
full_path = (
|
full_path = (
|
||||||
f"{root_dir}"
|
|
||||||
f"{self.aux_dir}/user_{self.user_id}/"
|
f"{self.aux_dir}/user_{self.user_id}/"
|
||||||
f"document_{self.document_id}/"
|
f"document_{self.document_id}/"
|
||||||
)
|
)
|
||||||
|
@ -221,8 +235,6 @@ class DocumentEp:
|
||||||
|
|
||||||
def copy_from(doc_ep, aux_dir):
|
def copy_from(doc_ep, aux_dir):
|
||||||
return DocumentEp(
|
return DocumentEp(
|
||||||
remote_endpoint=doc_ep.remote_endpoint,
|
|
||||||
local_endpoint=doc_ep.local_endpoint,
|
|
||||||
user_id=doc_ep.user_id,
|
user_id=doc_ep.user_id,
|
||||||
document_id=doc_ep.document_id,
|
document_id=doc_ep.document_id,
|
||||||
file_name=doc_ep.file_name,
|
file_name=doc_ep.file_name,
|
||||||
|
@ -250,7 +262,7 @@ class PageEp:
|
||||||
self.document_ep = document_ep
|
self.document_ep = document_ep
|
||||||
self.results_document_ep = DocumentEp.copy_from(
|
self.results_document_ep = DocumentEp.copy_from(
|
||||||
document_ep,
|
document_ep,
|
||||||
aux_dir="results"
|
aux_dir=AUX_DIR_RESULTS
|
||||||
)
|
)
|
||||||
self.page_count = page_count
|
self.page_count = page_count
|
||||||
self.page_num = page_num
|
self.page_num = page_num
|
||||||
|
|
|
@ -1,9 +1,29 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class Storage:
|
class Storage:
|
||||||
"""
|
"""
|
||||||
Storage class which works with Endpointsf
|
Storage class which works with Endpointsf
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __init__(self, location=None):
|
||||||
|
self._location = location
|
||||||
|
|
||||||
|
@property
|
||||||
|
def location(self):
|
||||||
|
return self._location
|
||||||
|
|
||||||
|
def path_doc(self, ep):
|
||||||
|
return os.path.join(
|
||||||
|
self.location,
|
||||||
|
ep.path_doc
|
||||||
|
)
|
||||||
|
|
||||||
|
def path_result(self, ep):
|
||||||
|
return os.path.join(
|
||||||
|
self.location, ep.path_result
|
||||||
|
)
|
||||||
|
|
||||||
def delete(self, ep):
|
def delete(self, ep):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -204,8 +204,6 @@ class TestPageEp(unittest.TestCase):
|
||||||
|
|
||||||
def test_versioned_page_ep(self):
|
def test_versioned_page_ep(self):
|
||||||
doc_ep = DocumentEp(
|
doc_ep = DocumentEp(
|
||||||
remote_endpoint=self.remote_ep,
|
|
||||||
local_endpoint=self.local_ep,
|
|
||||||
user_id=1,
|
user_id=1,
|
||||||
document_id=3,
|
document_id=3,
|
||||||
file_name="x.pdf"
|
file_name="x.pdf"
|
||||||
|
@ -229,8 +227,6 @@ class TestPageEp(unittest.TestCase):
|
||||||
page_ep.url() returns page_ep.txt_url()
|
page_ep.url() returns page_ep.txt_url()
|
||||||
"""
|
"""
|
||||||
doc_ep = DocumentEp(
|
doc_ep = DocumentEp(
|
||||||
remote_endpoint=self.remote_ep,
|
|
||||||
local_endpoint=self.local_ep,
|
|
||||||
user_id=1,
|
user_id=1,
|
||||||
document_id=3,
|
document_id=3,
|
||||||
file_name="x.pdf"
|
file_name="x.pdf"
|
||||||
|
@ -248,8 +244,6 @@ class TestPageEp(unittest.TestCase):
|
||||||
|
|
||||||
def test_ppmroot(self):
|
def test_ppmroot(self):
|
||||||
doc_ep = DocumentEp(
|
doc_ep = DocumentEp(
|
||||||
remote_endpoint=self.remote_ep,
|
|
||||||
local_endpoint=self.local_ep,
|
|
||||||
user_id=1,
|
user_id=1,
|
||||||
document_id=3,
|
document_id=3,
|
||||||
file_name="x.pdf"
|
file_name="x.pdf"
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
from mglib.endpoint import DocumentEp
|
||||||
|
from mglib.storage import Storage
|
||||||
|
|
||||||
|
|
||||||
class TestStep(unittest.TestCase):
|
class TestStep(unittest.TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
pass
|
storage = Storage()
|
||||||
|
|
||||||
|
ep = DocumentEp(
|
||||||
|
user_id=1,
|
||||||
|
document_id=2,
|
||||||
|
file_name='doku.pdf'
|
||||||
|
)
|
||||||
|
storage.delete(ep)
|
||||||
|
|
Loading…
Reference in New Issue