diff --git a/mglib/endpoint.py b/mglib/endpoint.py index 7c66acd..e1efe57 100644 --- a/mglib/endpoint.py +++ b/mglib/endpoint.py @@ -6,6 +6,9 @@ from botocore.errorfactory import ClientError logger = logging.getLogger(__name__) +AUX_DIR_DOCS = "docs" +AUX_DIR_RESULTS = "results" + def get_keyname(s3_url): """ @@ -115,8 +118,8 @@ class Endpoint: class DocumentEp: """ - Document Endpoint: - ://///// + Document Endpoint path: + ///// If version = 0, it is not included in Endpoint. Document's version is incremented everytime pdftk operation runs on it @@ -125,16 +128,12 @@ class DocumentEp: def __init__( self, - remote_endpoint, - local_endpoint, user_id, document_id, file_name, - aux_dir="docs", + aux_dir=AUX_DIR_DOCS, version=0 ): - self.remote_endpoint = remote_endpoint - self.local_endpoint = local_endpoint self.user_id = user_id self.document_id = document_id self.file_name = file_name @@ -157,11 +156,26 @@ class DocumentEp: return full_path @property - def dirname(self): - root_dir = f"{self.local_endpoint.dirname}" + def dirname_docs(self): + _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 = ( - f"{root_dir}" f"{self.aux_dir}/user_{self.user_id}/" f"document_{self.document_id}/" ) @@ -221,8 +235,6 @@ class DocumentEp: def copy_from(doc_ep, aux_dir): return DocumentEp( - remote_endpoint=doc_ep.remote_endpoint, - local_endpoint=doc_ep.local_endpoint, user_id=doc_ep.user_id, document_id=doc_ep.document_id, file_name=doc_ep.file_name, @@ -250,7 +262,7 @@ class PageEp: self.document_ep = document_ep self.results_document_ep = DocumentEp.copy_from( document_ep, - aux_dir="results" + aux_dir=AUX_DIR_RESULTS ) self.page_count = page_count self.page_num = page_num diff --git a/mglib/storage.py b/mglib/storage.py index c85fc5a..a3b70e2 100644 --- a/mglib/storage.py +++ b/mglib/storage.py @@ -1,9 +1,29 @@ +import os + class Storage: """ 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): pass diff --git a/test/test_endpoint.py b/test/test_endpoint.py index 19355f1..093df8a 100644 --- a/test/test_endpoint.py +++ b/test/test_endpoint.py @@ -204,8 +204,6 @@ class TestPageEp(unittest.TestCase): def test_versioned_page_ep(self): doc_ep = DocumentEp( - remote_endpoint=self.remote_ep, - local_endpoint=self.local_ep, user_id=1, document_id=3, file_name="x.pdf" @@ -229,8 +227,6 @@ class TestPageEp(unittest.TestCase): page_ep.url() returns page_ep.txt_url() """ doc_ep = DocumentEp( - remote_endpoint=self.remote_ep, - local_endpoint=self.local_ep, user_id=1, document_id=3, file_name="x.pdf" @@ -248,8 +244,6 @@ class TestPageEp(unittest.TestCase): def test_ppmroot(self): doc_ep = DocumentEp( - remote_endpoint=self.remote_ep, - local_endpoint=self.local_ep, user_id=1, document_id=3, file_name="x.pdf" diff --git a/test/test_storage.py b/test/test_storage.py index 9adffd3..6848520 100644 --- a/test/test_storage.py +++ b/test/test_storage.py @@ -1,7 +1,16 @@ import unittest +from mglib.endpoint import DocumentEp +from mglib.storage import Storage class TestStep(unittest.TestCase): def test_basic(self): - pass + storage = Storage() + + ep = DocumentEp( + user_id=1, + document_id=2, + file_name='doku.pdf' + ) + storage.delete(ep)