pullobj 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ # Commons
2
+ build/
3
+ bin/
4
+ dist/
5
+ nbdist/
6
+ out/
7
+ target/
8
+ logs/
9
+ *.log
10
+ *.pid
11
+ *.pid.lock
12
+ *.seed
13
+
14
+ # Java
15
+ *.class
16
+ *.jar
17
+ *.war
18
+ *.nar
19
+ *.ear
20
+
21
+ # Python
22
+ __pycache__/
23
+ venv/
24
+ *egg-info/
25
+ *.py[cod]
26
+ *.spec
27
+ .python-version
28
+ .venv
29
+
30
+ # Node
31
+ node_modules/
32
+ jspm_packages/
33
+ web_modules/
34
+ npm-debug.log
35
+ yarn-error.log
36
+ *.tsbuildinfo
37
+ .npm
38
+
39
+ # Miscellaneous
40
+ .sass-cache/
41
+ **/.angular/cache
42
+ connect.lock
43
+ coverage
44
+ libpeerconnection.log
45
+ testem.log
46
+ typings
47
+
48
+ # IDE
49
+ tmp/
50
+ .idea/
51
+ .project/
52
+ .settings/
53
+ .classpath/
54
+ .recommenders/
55
+ .vscode/
56
+ .vscode-test/
57
+ .history/
58
+ *.iml
59
+ *.iws
60
+ *.tmp
61
+ *.bak
62
+ *.swp
63
+ *~.nib
64
+ *.pydevproject
65
+ .cproject
66
+ .project
67
+ .metadata
68
+ .loadpath
69
+ .buildpath
70
+
71
+ # System
72
+ .DS_Store
73
+ Thumbs.db
74
+
75
+ # Local
76
+ local.properties
77
+ local.ini
78
+ local.json
79
+ .env
80
+ output/
pullobj-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2026 cvisinoni
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
pullobj-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: pullobj
3
+ Version: 0.1.0
4
+ Summary: A Python library for synchronizing remote objects to local files
5
+ Project-URL: Homepage, https://github.com/cvisinoni/pullobj
6
+ Project-URL: Issues, https://github.com/cvisinoni/pullobj/issues
7
+ Author: cvisinoni
8
+ License: Copyright (c) 2026 cvisinoni
9
+
10
+ Permission is hereby granted, free of charge, to any person
11
+ obtaining a copy of this software and associated documentation
12
+ files (the "Software"), to deal in the Software without
13
+ restriction, including without limitation the rights to use,
14
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the
16
+ Software is furnished to do so, subject to the following
17
+ conditions:
18
+
19
+ The above copyright notice and this permission notice shall be
20
+ included in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29
+ OTHER DEALINGS IN THE SOFTWARE.
30
+ License-File: LICENSE
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Programming Language :: Python :: 3
33
+ Requires-Python: >=3.9
34
+ Description-Content-Type: text/markdown
35
+
36
+ # pullobj
37
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cvisinoni/pullobj/blob/master/LICENSE)
38
+
39
+ pullobj is a Python library for building clients that connect to a generic remote server
40
+ (databases, cloud storage, object collections) and synchronize all remote objects to a local directory.
41
+ It provides a simple abstraction to keep a local mirror always up to date with the remote source.
42
+
43
+
44
+ ## Features
45
+ - Generic client for remote servers
46
+ - Full download of remote objects to local storage
47
+ - On-demand synchronization (remote → local)
48
+ - Supports heterogeneous objects (JSON, Excel, images, code, etc.)
49
+ - Extensible design for custom backends
50
+
51
+
52
+ ## Installation
53
+ ```bash
54
+ pip install pullobj
55
+ ```
56
+
57
+ ## Core Concept
58
+ - A Client represents a remote source
59
+ - The client knows how to list and fetch remote objects
60
+ - pullobj handles local storage and synchronization logic
61
+
62
+
63
+ ## Contributing
64
+ If you'd like to contribute to pullobj, feel free to fork this repository,
65
+ make your changes, and submit a pull request.
66
+ We welcome contributions of all kinds, whether it's fixing a bug,
67
+ adding a new feature, or improving documentation.
68
+
69
+
70
+ ## License
71
+ This project is MIT licensed. See the [LICENSE](LICENSE) file for details.
72
+
73
+
74
+ ## Support
75
+ If you have any questions, issues, or suggestions regarding pullobj,
76
+ please [open an issue](https://github.com/cvisinoni/pullobj/issues) on GitHub.
77
+ We'd love to hear from you!
@@ -0,0 +1,42 @@
1
+ # pullobj
2
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cvisinoni/pullobj/blob/master/LICENSE)
3
+
4
+ pullobj is a Python library for building clients that connect to a generic remote server
5
+ (databases, cloud storage, object collections) and synchronize all remote objects to a local directory.
6
+ It provides a simple abstraction to keep a local mirror always up to date with the remote source.
7
+
8
+
9
+ ## Features
10
+ - Generic client for remote servers
11
+ - Full download of remote objects to local storage
12
+ - On-demand synchronization (remote → local)
13
+ - Supports heterogeneous objects (JSON, Excel, images, code, etc.)
14
+ - Extensible design for custom backends
15
+
16
+
17
+ ## Installation
18
+ ```bash
19
+ pip install pullobj
20
+ ```
21
+
22
+ ## Core Concept
23
+ - A Client represents a remote source
24
+ - The client knows how to list and fetch remote objects
25
+ - pullobj handles local storage and synchronization logic
26
+
27
+
28
+ ## Contributing
29
+ If you'd like to contribute to pullobj, feel free to fork this repository,
30
+ make your changes, and submit a pull request.
31
+ We welcome contributions of all kinds, whether it's fixing a bug,
32
+ adding a new feature, or improving documentation.
33
+
34
+
35
+ ## License
36
+ This project is MIT licensed. See the [LICENSE](LICENSE) file for details.
37
+
38
+
39
+ ## Support
40
+ If you have any questions, issues, or suggestions regarding pullobj,
41
+ please [open an issue](https://github.com/cvisinoni/pullobj/issues) on GitHub.
42
+ We'd love to hear from you!
@@ -0,0 +1,8 @@
1
+ from .client import Client
2
+ from .element import Element
3
+
4
+
5
+ __all__ = [
6
+ 'Client',
7
+ 'Element',
8
+ ]
@@ -0,0 +1,69 @@
1
+ from .element import Element
2
+ from .utils import load_json, save_json
3
+ from .logger import log
4
+ from os import walk, listdir, rmdir
5
+ from pathlib import Path
6
+
7
+
8
+ class Client:
9
+
10
+ def __init__(self, root: str | Path):
11
+ self.root = Path(root)
12
+ self.objectsinfo = dict()
13
+ self.element_class = type[Element](
14
+ Element.__name__, (Element,), dict(root=self.root)
15
+ )
16
+
17
+ @property
18
+ def objectsinfo_file(self):
19
+ return self.root / '.objectsinfo.json'
20
+
21
+ def load_objectsinfo(self):
22
+ if self.objectsinfo_file.exists():
23
+ content = load_json(self.objectsinfo_file)
24
+ for key, data in content.items():
25
+ element = self.element_class.from_dict(data)
26
+ self.objectsinfo[key] = element
27
+
28
+ def save_objectsinfo(self):
29
+ save_json(self.objectsinfo_file, {
30
+ key: element.to_dict() for key, element in self.objectsinfo.items()
31
+ })
32
+
33
+ def retrieve_elements_dict(self):
34
+ raise NotImplementedError('Not implemented')
35
+
36
+ def retrieve_an_element_content(self, element: Element):
37
+ raise NotImplementedError('Not implemented')
38
+
39
+ def pull(self):
40
+ log.debug(f'--- start pull elements for client {self.root} ---')
41
+ # load old objectsinfo and retrieve new dict
42
+ self.load_objectsinfo()
43
+ elements_dict = self.retrieve_elements_dict()
44
+
45
+ # delete elements that are not in the new dict
46
+ for key, element in list(self.objectsinfo.items()):
47
+ if key not in elements_dict:
48
+ element.delete()
49
+ self.objectsinfo.pop(key)
50
+
51
+ # delete empty folders
52
+ walk_list = list(walk(self.root))
53
+ for top, dirs, files in walk_list[::-1]:
54
+ if len(listdir(top)) == 0:
55
+ rmdir(top)
56
+
57
+ # export elements that are in the new dict
58
+ for key, value in elements_dict.items():
59
+ new_element: Element = self.element_class.from_dict(value)
60
+ if key in self.objectsinfo:
61
+ old_element = self.objectsinfo[key]
62
+ if old_element.last_update_date >= new_element.last_update_date and old_element.file.is_file():
63
+ continue
64
+ content = self.retrieve_an_element_content(new_element)
65
+ new_element.save(content)
66
+ self.objectsinfo[key] = new_element
67
+
68
+ # update file objectsinfo
69
+ self.save_objectsinfo()
@@ -0,0 +1,55 @@
1
+ from .logger import log
2
+ from datetime import datetime
3
+ from pathlib import Path
4
+ from copy import deepcopy
5
+ import os
6
+
7
+
8
+ class Element:
9
+
10
+ root: Path = None
11
+
12
+ def __init__(self, key: str, path: str, last_update_date: datetime, **kwargs):
13
+ self.key = key
14
+ self.path = path if not path.startswith('/') else path[1:]
15
+ self.last_update_date = last_update_date
16
+ self.kwargs = kwargs
17
+
18
+ @classmethod
19
+ def from_dict(cls, data: dict):
20
+ kwargs = deepcopy(data)
21
+ key = kwargs.pop('key')
22
+ path = kwargs.pop('path')
23
+ last_update_date = kwargs.pop('last_update_date')
24
+ if isinstance(last_update_date, str):
25
+ last_update_date = datetime.fromisoformat(last_update_date)
26
+ return cls(key, path, last_update_date, **kwargs)
27
+
28
+ @property
29
+ def file(self):
30
+ return self.root / self.path
31
+
32
+ def to_dict(self):
33
+ result = dict(
34
+ key=self.key,
35
+ path=self.path,
36
+ last_update_date=self.last_update_date.isoformat(),
37
+ )
38
+ for key, value in self.kwargs.items():
39
+ result[key] = value
40
+ return result
41
+
42
+ def delete(self):
43
+ if self.file.is_file():
44
+ log.debug(f'deleting {self.file}')
45
+ os.remove(self.file)
46
+
47
+ def save(self, content: str | bytes):
48
+ if isinstance(content, str):
49
+ content = content.encode('utf-8')
50
+ if isinstance(content, bytes):
51
+ log.debug(f'saving {self.file}')
52
+ self.file.parent.mkdir(parents=True, exist_ok=True)
53
+ self.file.write_bytes(content)
54
+ else:
55
+ log.warning(f'content of {self.key} is not str or bytes ({type(content)})')
@@ -0,0 +1,4 @@
1
+ import logging
2
+
3
+
4
+ log = logging.getLogger(__package__)
@@ -0,0 +1,13 @@
1
+ from pathlib import Path
2
+ import json
3
+
4
+
5
+ def load_json(file: Path) -> dict | list:
6
+ with open(file, mode='r', encoding='utf-8') as fp:
7
+ return json.load(fp)
8
+
9
+
10
+ def save_json(file: Path, data: dict | list):
11
+ Path(file).parent.mkdir(parents=True, exist_ok=True)
12
+ with open(file, mode='w', encoding='utf-8') as fp:
13
+ json.dump(data, fp, indent=' ')
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+
3
+ requires = ["hatchling>=1.26"]
4
+ build-backend = "hatchling.build"
5
+
6
+
7
+ [project]
8
+
9
+ name = "pullobj"
10
+ version = "0.1.0"
11
+ authors = [{ name = "cvisinoni" }]
12
+ description = "A Python library for synchronizing remote objects to local files"
13
+ readme = { file = "README.md", content-type = "text/markdown" }
14
+ requires-python = ">=3.9"
15
+ license = { file = "LICENSE" }
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+
21
+
22
+ [project.urls]
23
+
24
+ Homepage = "https://github.com/cvisinoni/pullobj"
25
+ Issues = "https://github.com/cvisinoni/pullobj/issues"
26
+
27
+
28
+ [tool.hatch.build]
29
+
30
+ exclude = ["tests/**", "*.pyc", ".github/**", '/example.py']