bluer-objects 6.5.1__py3-none-any.whl → 6.7.1__py3-none-any.whl
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.
Potentially problematic release.
This version of bluer-objects might be problematic. Click here for more details.
- bluer_objects/__init__.py +1 -1
- bluer_objects/objects.py +2 -6
- {bluer_objects-6.5.1.dist-info → bluer_objects-6.7.1.dist-info}/METADATA +2 -2
- {bluer_objects-6.5.1.dist-info → bluer_objects-6.7.1.dist-info}/RECORD +7 -25
- bluer_objects/mysql/cache/__init__.py +0 -8
- bluer_objects/mysql/cache/__main__.py +0 -91
- bluer_objects/mysql/cache/functions.py +0 -181
- bluer_objects/mysql/relations/__init__.py +0 -9
- bluer_objects/mysql/relations/__main__.py +0 -138
- bluer_objects/mysql/relations/functions.py +0 -180
- bluer_objects/mysql/table.py +0 -144
- bluer_objects/mysql/tags/__init__.py +0 -1
- bluer_objects/mysql/tags/__main__.py +0 -130
- bluer_objects/mysql/tags/functions.py +0 -203
- bluer_objects/storage/__init__.py +0 -3
- bluer_objects/storage/__main__.py +0 -114
- bluer_objects/storage/classes.py +0 -237
- bluer_objects/tests/test_mysql_cache.py +0 -14
- bluer_objects/tests/test_mysql_relations.py +0 -16
- bluer_objects/tests/test_mysql_table.py +0 -9
- bluer_objects/tests/test_mysql_tags.py +0 -13
- bluer_objects/tests/test_storage.py +0 -7
- {bluer_objects-6.5.1.dist-info → bluer_objects-6.7.1.dist-info}/WHEEL +0 -0
- {bluer_objects-6.5.1.dist-info → bluer_objects-6.7.1.dist-info}/licenses/LICENSE +0 -0
- {bluer_objects-6.5.1.dist-info → bluer_objects-6.7.1.dist-info}/top_level.txt +0 -0
bluer_objects/__init__.py
CHANGED
bluer_objects/objects.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bluer_objects
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.7.1
|
|
4
4
|
Summary: 🌀 data objects for Bash.
|
|
5
5
|
Home-page: https://github.com/kamangir/bluer-objects
|
|
6
6
|
Author: Arash Abadpour (Kamangir)
|
|
@@ -52,6 +52,6 @@ Also home to [blue README](https://github.com/kamangir/bluer-objects/blob/main/b
|
|
|
52
52
|
|
|
53
53
|
[](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml) [](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml) [](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml) [](https://pypi.org/project/bluer-objects/) [](https://pypistats.org/packages/bluer-objects)
|
|
54
54
|
|
|
55
|
-
built by 🌀 [`blue_options-4.240.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌀 [`bluer_objects-6.
|
|
55
|
+
built by 🌀 [`blue_options-4.240.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌀 [`bluer_objects-6.7.1`](https://github.com/kamangir/bluer-objects).
|
|
56
56
|
|
|
57
57
|
built by 🌀 [`blueness-3.96.1`](https://github.com/kamangir/blueness).
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
bluer_objects/__init__.py,sha256=
|
|
1
|
+
bluer_objects/__init__.py,sha256=gZs-zJQ1NHJ6DS7_-ffxKR7dUKkPpdfXyAhdSFTgEVg,309
|
|
2
2
|
bluer_objects/__main__.py,sha256=Yqfov833_hJuRne19WrGhT5DWAPtdffpoMxeSXS7EGw,359
|
|
3
3
|
bluer_objects/config.env,sha256=H21xLEVlI3qiDiOrG3Tzgkb8vKSQXCr3kr9jzoU7I-4,508
|
|
4
4
|
bluer_objects/env.py,sha256=L8TmIm8mp0OLUX1tV1HlLyKD2YqvVv8QZuUbdeOkuZA,1910
|
|
5
5
|
bluer_objects/markdown.py,sha256=PhAwCTHIisO9qOpKHeb63U5oD9Zi8LnIQKTx_OWS4wE,938
|
|
6
|
-
bluer_objects/objects.py,sha256=
|
|
6
|
+
bluer_objects/objects.py,sha256=aizYA0_hleEJoemScro5AkPXGdcK0MXRC_sryiCZdOE,3461
|
|
7
7
|
bluer_objects/path.py,sha256=mn5wM4a-rdIlVA7ePBSUxZuTKRT7VnqmGUQp93RjFdc,3944
|
|
8
8
|
bluer_objects/sample.env,sha256=HBpf1DRNOkN29g79B9HJUceVJHddADxexsVlnGwLLbI,860
|
|
9
9
|
bluer_objects/urls.py,sha256=paHaYlLMQOI46-EYNch5ohu9Q09BMkF2vvJy1QufrVI,19
|
|
@@ -105,19 +105,6 @@ bluer_objects/mlflow/objects.py,sha256=dzE1OJRMcJmqSKE27X7EoCnDTGDF3mTE1atcspVXG
|
|
|
105
105
|
bluer_objects/mlflow/runs.py,sha256=ttsyDhxF5_cUs_Ul-fvtrRIQc14ZMteAPyEMP_mR6P0,2414
|
|
106
106
|
bluer_objects/mlflow/tags.py,sha256=MbuZMe8Udfevix6IyBRXLsqyZVG2K8PILPkqA7xevmk,2473
|
|
107
107
|
bluer_objects/mlflow/testing.py,sha256=43WfVzQNxB-ar513J2Zfb0B3JOLaFKxbOSKOF1BkmLM,840
|
|
108
|
-
bluer_objects/mysql/table.py,sha256=3aIlJzWpAnOlhpSGhmIbP7lJLqE15dF9XlAx1lViqsQ,3817
|
|
109
|
-
bluer_objects/mysql/cache/__init__.py,sha256=ITD1N0CP7Uwf50iBiAYMqV7sTg03iVxQgWBSkvdTGWM,126
|
|
110
|
-
bluer_objects/mysql/cache/__main__.py,sha256=ugPCsgGCgYGshha9VPGBtAVLE0-HtEnGiDgZ1yucOKA,1798
|
|
111
|
-
bluer_objects/mysql/cache/functions.py,sha256=T5dIdYTA0ct3rFX4-v_LyrQ6IkoN7mFrZKYa8A5FgCg,3882
|
|
112
|
-
bluer_objects/mysql/relations/__init__.py,sha256=yiv_QtYVN2UAK3B5d-uOuhreXCZQIktEvaDvbgeKuNA,139
|
|
113
|
-
bluer_objects/mysql/relations/__main__.py,sha256=hJEk5RPe_F4R2kqTuSNljAcklz22oSWpyhSpAX5jzvY,3072
|
|
114
|
-
bluer_objects/mysql/relations/functions.py,sha256=-5XepOnKDdPald-_2fxYiDATv0H8jzA3fBQ3JvWVGXs,4346
|
|
115
|
-
bluer_objects/mysql/tags/__init__.py,sha256=kpbtBWTwwA5lj3GxwTuA8ll0g1gzds-Og0WmOhRgNEU,80
|
|
116
|
-
bluer_objects/mysql/tags/__main__.py,sha256=hkp1i5ESPXy1X8fqB56hKsjcIcJIzVmGGlhqhb3hIIw,2390
|
|
117
|
-
bluer_objects/mysql/tags/functions.py,sha256=c7xwLApa-wdP1Z79RFzCLyoM28F0afrnwcAngrUvAyw,5068
|
|
118
|
-
bluer_objects/storage/__init__.py,sha256=LNWVSCTpigRjwSWZtjfZVPUkx_vEqurka2-MmyI5HKk,72
|
|
119
|
-
bluer_objects/storage/__main__.py,sha256=VqmZbNYtgYZz5n42phLL5DDHns1OZaI_bdhpYAJDfk0,2489
|
|
120
|
-
bluer_objects/storage/classes.py,sha256=Vb_K5Xm3StPNF7anHnJWf9ag7TedwgHw6PyIqmACQVY,6608
|
|
121
108
|
bluer_objects/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
122
109
|
bluer_objects/tests/test_README.py,sha256=5D4UV8VcjbeAPThsYVynYtVFuP8gwMAhIjEWuOQZsWs,89
|
|
123
110
|
bluer_objects/tests/test_env.py,sha256=_okfG-X2BGLsI134CxFCrAZjqWNBv_Lou5CVZK_qzTU,586
|
|
@@ -134,16 +121,11 @@ bluer_objects/tests/test_logger_matrix.py,sha256=krJPUdlQTLD8P8EjkrlmJVw6Iylwbl8
|
|
|
134
121
|
bluer_objects/tests/test_markdown.py,sha256=GOsvHFUlPVamMqJSCHL9BKR6C5sUHHowOMExxHoHoME,216
|
|
135
122
|
bluer_objects/tests/test_metadata.py,sha256=y9dAEPWO2U5wbOhf41CdElywPDMm6lJG3TZJG6l2sJs,4263
|
|
136
123
|
bluer_objects/tests/test_mlflow.py,sha256=04byWcVJJ8yjrYq_f54Lgr-tvh9L18zIX8KIbsjuTh4,1379
|
|
137
|
-
bluer_objects/tests/test_mysql_cache.py,sha256=oTnpUrnCjuX0YUEwdfar-4TtkU9sQPZwhe2u94GcH8s,292
|
|
138
|
-
bluer_objects/tests/test_mysql_relations.py,sha256=jRH93kZM_30f0VpomoHsJSu6Zzv0hqlIND6VJFdP1hY,382
|
|
139
|
-
bluer_objects/tests/test_mysql_table.py,sha256=7EMqmRqpQUniADcW9ADCcua809U3zhFWzZZiEL25tqE,160
|
|
140
|
-
bluer_objects/tests/test_mysql_tags.py,sha256=mNlKfT3ZwvNkVIW_hA8p5wVKDbobqzlr7-alK40QJ8g,321
|
|
141
124
|
bluer_objects/tests/test_objects.py,sha256=GNW4zbswrrK-kyyeCmfwACF5s1npVVXli_18q_6LaJc,4216
|
|
142
125
|
bluer_objects/tests/test_path.py,sha256=JjONWyhZyMM_u1SzD1RI_iZ5vYJDUe-B51fbbHczIig,85
|
|
143
|
-
bluer_objects/tests/test_storage.py,sha256=I24GGptOPhfelhvn9DGt6TW3UNjg3pubPsCKmmE7orc,111
|
|
144
126
|
bluer_objects/tests/test_version.py,sha256=Lyf3PMcA22e17BNRk_2VgPrtao6dWEgVoXo68Uds8SE,75
|
|
145
|
-
bluer_objects-6.
|
|
146
|
-
bluer_objects-6.
|
|
147
|
-
bluer_objects-6.
|
|
148
|
-
bluer_objects-6.
|
|
149
|
-
bluer_objects-6.
|
|
127
|
+
bluer_objects-6.7.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
|
|
128
|
+
bluer_objects-6.7.1.dist-info/METADATA,sha256=JQZXy3gL3Dkp99UN5Uyv52Qdldr0Fu4bA46_BW70CB8,2652
|
|
129
|
+
bluer_objects-6.7.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
130
|
+
bluer_objects-6.7.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
|
|
131
|
+
bluer_objects-6.7.1.dist-info/RECORD,,
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
|
|
3
|
-
from blueness import module
|
|
4
|
-
from blueness.argparse.generic import sys_exit
|
|
5
|
-
|
|
6
|
-
from bluer_objects import NAME
|
|
7
|
-
from bluer_objects.mysql.cache.functions import create, clone, read, write, search
|
|
8
|
-
from bluer_objects.logger import logger
|
|
9
|
-
|
|
10
|
-
NAME = module.name(__file__, NAME)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
parser = argparse.ArgumentParser(NAME)
|
|
14
|
-
parser.add_argument(
|
|
15
|
-
"task",
|
|
16
|
-
type=str,
|
|
17
|
-
default="read",
|
|
18
|
-
help="clone,create,read,search,write",
|
|
19
|
-
)
|
|
20
|
-
parser.add_argument(
|
|
21
|
-
"--all",
|
|
22
|
-
default=0,
|
|
23
|
-
type=int,
|
|
24
|
-
)
|
|
25
|
-
parser.add_argument(
|
|
26
|
-
"--dataframe",
|
|
27
|
-
default=0,
|
|
28
|
-
type=int,
|
|
29
|
-
)
|
|
30
|
-
parser.add_argument(
|
|
31
|
-
"--destination",
|
|
32
|
-
type=str,
|
|
33
|
-
default="",
|
|
34
|
-
)
|
|
35
|
-
parser.add_argument(
|
|
36
|
-
"--keyword",
|
|
37
|
-
type=str,
|
|
38
|
-
)
|
|
39
|
-
parser.add_argument(
|
|
40
|
-
"--like",
|
|
41
|
-
default=0,
|
|
42
|
-
type=int,
|
|
43
|
-
)
|
|
44
|
-
parser.add_argument(
|
|
45
|
-
"--source",
|
|
46
|
-
type=str,
|
|
47
|
-
default="",
|
|
48
|
-
)
|
|
49
|
-
parser.add_argument(
|
|
50
|
-
"--unique",
|
|
51
|
-
default=1,
|
|
52
|
-
type=int,
|
|
53
|
-
help="cache.read('unique')",
|
|
54
|
-
)
|
|
55
|
-
parser.add_argument(
|
|
56
|
-
"--value",
|
|
57
|
-
type=str,
|
|
58
|
-
default="unknown",
|
|
59
|
-
)
|
|
60
|
-
args = parser.parse_args()
|
|
61
|
-
|
|
62
|
-
success = False
|
|
63
|
-
if args.task == "clone":
|
|
64
|
-
success = clone(args.source, args.destination)
|
|
65
|
-
elif args.task == "create":
|
|
66
|
-
success = create()
|
|
67
|
-
elif args.task == "read":
|
|
68
|
-
output = read(
|
|
69
|
-
args.keyword,
|
|
70
|
-
all=args.all,
|
|
71
|
-
like=args.like,
|
|
72
|
-
dataframe=args.dataframe,
|
|
73
|
-
unique=args.unique,
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
print(
|
|
77
|
-
("None" if output.empty else output.drop(columns=["log_id"]))
|
|
78
|
-
if args.dataframe
|
|
79
|
-
else output
|
|
80
|
-
)
|
|
81
|
-
success = True
|
|
82
|
-
elif args.task == "search":
|
|
83
|
-
for keyword, value in search(args.keyword).items():
|
|
84
|
-
print(f"{keyword}: {value}")
|
|
85
|
-
success = True
|
|
86
|
-
elif args.task == "write":
|
|
87
|
-
success = write(args.keyword, args.value)
|
|
88
|
-
else:
|
|
89
|
-
success = None
|
|
90
|
-
|
|
91
|
-
sys_exit(logger, NAME, args.task, success)
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List
|
|
2
|
-
from functools import reduce
|
|
3
|
-
import json
|
|
4
|
-
|
|
5
|
-
from blue_options import string
|
|
6
|
-
|
|
7
|
-
from bluer_objects.mysql.table import Table
|
|
8
|
-
from bluer_objects.logger import logger
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
columns = "keyword,value,timestamp".split(",")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def create() -> bool:
|
|
15
|
-
return Table.Create(
|
|
16
|
-
"cache",
|
|
17
|
-
[
|
|
18
|
-
"keyword VARCHAR(1024) NOT NULL",
|
|
19
|
-
"value VARCHAR(4096) NOT NULL",
|
|
20
|
-
],
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def clone(
|
|
25
|
-
source: str,
|
|
26
|
-
destination: str,
|
|
27
|
-
) -> bool:
|
|
28
|
-
lut = search(f"{source}.%")
|
|
29
|
-
|
|
30
|
-
lut = {
|
|
31
|
-
"{}.{}".format(
|
|
32
|
-
destination,
|
|
33
|
-
string.after(
|
|
34
|
-
keyword,
|
|
35
|
-
f"{source}.",
|
|
36
|
-
),
|
|
37
|
-
): value
|
|
38
|
-
for keyword, value in lut.items()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return reduce(
|
|
42
|
-
lambda x, y: x and y,
|
|
43
|
-
[write(keyword, value) for keyword, value in lut.items()],
|
|
44
|
-
True,
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def read(
|
|
49
|
-
keyword: str,
|
|
50
|
-
all: bool = False,
|
|
51
|
-
dataframe: bool = False,
|
|
52
|
-
like: bool = False,
|
|
53
|
-
unique: bool = False,
|
|
54
|
-
) -> Any:
|
|
55
|
-
if dataframe:
|
|
56
|
-
all = True
|
|
57
|
-
|
|
58
|
-
table = Table(name="cache")
|
|
59
|
-
|
|
60
|
-
if isinstance(keyword, list):
|
|
61
|
-
keyword = ".".join(keyword)
|
|
62
|
-
|
|
63
|
-
if not table.connect():
|
|
64
|
-
return None
|
|
65
|
-
|
|
66
|
-
success, output = table.execute(
|
|
67
|
-
(
|
|
68
|
-
"SELECT {} FROM ".format(
|
|
69
|
-
",".join(["c.{}".format(column) for column in columns])
|
|
70
|
-
)
|
|
71
|
-
+ "abcli.cache c "
|
|
72
|
-
)
|
|
73
|
-
+ (
|
|
74
|
-
(
|
|
75
|
-
"INNER JOIN ( "
|
|
76
|
-
"SELECT keyword, MAX(timestamp) AS max_timestamp "
|
|
77
|
-
"From abcli.cache "
|
|
78
|
-
"GROUP BY keyword "
|
|
79
|
-
") cm ON c.keyword = cm.keyword AND c.timestamp = cm.max_timestamp "
|
|
80
|
-
)
|
|
81
|
-
if unique
|
|
82
|
-
else ""
|
|
83
|
-
)
|
|
84
|
-
+ (
|
|
85
|
-
"WHERE c.keyword {} '{}' ".format("like" if like else "=", keyword)
|
|
86
|
-
+ "ORDER BY c.timestamp DESC "
|
|
87
|
-
+ "{};".format(
|
|
88
|
-
"" if all else "LIMIT 1",
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
)
|
|
92
|
-
if not success:
|
|
93
|
-
return None
|
|
94
|
-
|
|
95
|
-
if not table.disconnect():
|
|
96
|
-
return None
|
|
97
|
-
|
|
98
|
-
output = [
|
|
99
|
-
{keyword: item for keyword, item in zip(columns, thing)} for thing in output
|
|
100
|
-
]
|
|
101
|
-
|
|
102
|
-
if not dataframe:
|
|
103
|
-
output = [item["value"] for item in output]
|
|
104
|
-
|
|
105
|
-
if not all:
|
|
106
|
-
output = "" if not output else output[0]
|
|
107
|
-
|
|
108
|
-
if dataframe:
|
|
109
|
-
import pandas as pd
|
|
110
|
-
|
|
111
|
-
output = pd.DataFrame.from_dict(output)
|
|
112
|
-
|
|
113
|
-
return output
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def search(keyword: str) -> Dict[str, str]:
|
|
117
|
-
table = Table(name="cache")
|
|
118
|
-
|
|
119
|
-
if isinstance(keyword, list):
|
|
120
|
-
keyword = ".".join(keyword)
|
|
121
|
-
|
|
122
|
-
if not table.connect():
|
|
123
|
-
return {}
|
|
124
|
-
|
|
125
|
-
success, output = table.execute(
|
|
126
|
-
"SELECT keyword,value FROM abcli.cache "
|
|
127
|
-
f"WHERE keyword like '{keyword}' "
|
|
128
|
-
"ORDER BY timestamp ASC;"
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
if success:
|
|
132
|
-
success = table.disconnect()
|
|
133
|
-
|
|
134
|
-
return {thing[0]: thing[1] for thing in output} if success else {}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def search_value(value: str) -> List[str]:
|
|
138
|
-
table = Table(name="cache")
|
|
139
|
-
|
|
140
|
-
if not table.connect():
|
|
141
|
-
return []
|
|
142
|
-
|
|
143
|
-
success, output = table.execute(
|
|
144
|
-
"SELECT keyword,value FROM abcli.cache "
|
|
145
|
-
f"WHERE value = '{value}' "
|
|
146
|
-
"ORDER BY timestamp DESC;"
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
if success:
|
|
150
|
-
success = table.disconnect()
|
|
151
|
-
|
|
152
|
-
return [thing[0] for thing in output] if success else []
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def write(
|
|
156
|
-
keyword: str,
|
|
157
|
-
value: str,
|
|
158
|
-
) -> bool:
|
|
159
|
-
table = Table(name="cache")
|
|
160
|
-
|
|
161
|
-
if isinstance(keyword, list):
|
|
162
|
-
keyword = ".".join(keyword)
|
|
163
|
-
|
|
164
|
-
if isinstance(value, dict):
|
|
165
|
-
value = json.dumps(value)
|
|
166
|
-
|
|
167
|
-
if not table.connect():
|
|
168
|
-
return False
|
|
169
|
-
|
|
170
|
-
success = table.insert(
|
|
171
|
-
["keyword", "value"],
|
|
172
|
-
[keyword, value],
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
if success:
|
|
176
|
-
success = table.disconnect()
|
|
177
|
-
|
|
178
|
-
if success:
|
|
179
|
-
logger.info("cache[{}] <- {}".format(keyword, value))
|
|
180
|
-
|
|
181
|
-
return success
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
|
|
3
|
-
from blueness import module
|
|
4
|
-
from blueness.argparse.generic import sys_exit
|
|
5
|
-
|
|
6
|
-
from bluer_objects import file, NAME
|
|
7
|
-
from bluer_objects.mysql.relations.functions import (
|
|
8
|
-
clone,
|
|
9
|
-
create,
|
|
10
|
-
get,
|
|
11
|
-
search,
|
|
12
|
-
set_,
|
|
13
|
-
inverse_of,
|
|
14
|
-
list_of,
|
|
15
|
-
)
|
|
16
|
-
from bluer_objects.logger import logger
|
|
17
|
-
|
|
18
|
-
NAME = module.name(__file__, NAME)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
parser = argparse.ArgumentParser(NAME)
|
|
22
|
-
parser.add_argument(
|
|
23
|
-
"task",
|
|
24
|
-
type=str,
|
|
25
|
-
default="get",
|
|
26
|
-
help="clone|create|get|list|search|set",
|
|
27
|
-
)
|
|
28
|
-
parser.add_argument(
|
|
29
|
-
"--count",
|
|
30
|
-
type=int,
|
|
31
|
-
default=-1,
|
|
32
|
-
)
|
|
33
|
-
parser.add_argument(
|
|
34
|
-
"--delim",
|
|
35
|
-
type=str,
|
|
36
|
-
default=", ",
|
|
37
|
-
)
|
|
38
|
-
parser.add_argument(
|
|
39
|
-
"--filename",
|
|
40
|
-
type=str,
|
|
41
|
-
)
|
|
42
|
-
parser.add_argument(
|
|
43
|
-
"--item_name",
|
|
44
|
-
default="object",
|
|
45
|
-
type=str,
|
|
46
|
-
)
|
|
47
|
-
parser.add_argument(
|
|
48
|
-
"--log",
|
|
49
|
-
default=1,
|
|
50
|
-
type=int,
|
|
51
|
-
help="0|1",
|
|
52
|
-
)
|
|
53
|
-
parser.add_argument(
|
|
54
|
-
"--object_1",
|
|
55
|
-
type=str,
|
|
56
|
-
)
|
|
57
|
-
parser.add_argument(
|
|
58
|
-
"--object_2",
|
|
59
|
-
type=str,
|
|
60
|
-
)
|
|
61
|
-
parser.add_argument(
|
|
62
|
-
"--relation",
|
|
63
|
-
default="",
|
|
64
|
-
type=str,
|
|
65
|
-
)
|
|
66
|
-
parser.add_argument(
|
|
67
|
-
"--return_list",
|
|
68
|
-
type=int,
|
|
69
|
-
default=0,
|
|
70
|
-
)
|
|
71
|
-
args = parser.parse_args()
|
|
72
|
-
|
|
73
|
-
delim = " " if args.delim == "space" else args.delim
|
|
74
|
-
|
|
75
|
-
success = False
|
|
76
|
-
if args.task == "clone":
|
|
77
|
-
success = clone(args.object_1, args.object_2)
|
|
78
|
-
elif args.task == "create":
|
|
79
|
-
success = create()
|
|
80
|
-
elif args.task == "get":
|
|
81
|
-
relation = get(args.object_1, args.object_2)
|
|
82
|
-
if args.log:
|
|
83
|
-
logger.info(
|
|
84
|
-
f"{args.object_1} -{f'{relation}->' if relation else 'X-'} {args.object_2}"
|
|
85
|
-
)
|
|
86
|
-
else:
|
|
87
|
-
print(relation)
|
|
88
|
-
success = True
|
|
89
|
-
elif args.task == "list":
|
|
90
|
-
if args.return_list:
|
|
91
|
-
output = [relation for relation in list_of if relation]
|
|
92
|
-
|
|
93
|
-
if args.count != -1:
|
|
94
|
-
output = output[: args.count]
|
|
95
|
-
|
|
96
|
-
if args.log:
|
|
97
|
-
logger.info(f"{len(output):,} relations(s): {delim.join(output)}")
|
|
98
|
-
else:
|
|
99
|
-
print(delim.join(output))
|
|
100
|
-
else:
|
|
101
|
-
if args.log:
|
|
102
|
-
for thing in sorted(
|
|
103
|
-
[
|
|
104
|
-
"{} : {}".format(this, that)
|
|
105
|
-
for this, that in inverse_of.items()
|
|
106
|
-
if this
|
|
107
|
-
]
|
|
108
|
-
):
|
|
109
|
-
logger.info(thing)
|
|
110
|
-
else:
|
|
111
|
-
print(
|
|
112
|
-
delim.join(
|
|
113
|
-
[
|
|
114
|
-
"{}:{}".format(this, that)
|
|
115
|
-
for this, that in inverse_of.items()
|
|
116
|
-
if this
|
|
117
|
-
]
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
success = True
|
|
121
|
-
elif args.task == "search":
|
|
122
|
-
output = search(args.object_1, args.relation, args.count)
|
|
123
|
-
|
|
124
|
-
if args.relation:
|
|
125
|
-
if args.log:
|
|
126
|
-
logger.info(f"{len(output):,} {args.item_name}(s): {delim.join(output)}")
|
|
127
|
-
else:
|
|
128
|
-
print(delim.join(output))
|
|
129
|
-
else:
|
|
130
|
-
print(output)
|
|
131
|
-
|
|
132
|
-
success = file.save_json(args.filename, output) if args.filename else True
|
|
133
|
-
elif args.task == "set":
|
|
134
|
-
success = set_(args.object_1, args.object_2, args.relation)
|
|
135
|
-
else:
|
|
136
|
-
success = None
|
|
137
|
-
|
|
138
|
-
sys_exit(logger, NAME, args.task, success, log=args.log)
|