bluer-objects 6.4.1__py3-none-any.whl → 6.6.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 CHANGED
@@ -4,7 +4,7 @@ ICON = "🌀"
4
4
 
5
5
  DESCRIPTION = f"{ICON} data objects for Bash."
6
6
 
7
- VERSION = "6.4.1"
7
+ VERSION = "6.6.1"
8
8
 
9
9
  REPO_NAME = "bluer-objects"
10
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_objects
3
- Version: 6.4.1
3
+ Version: 6.6.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
  [![pylint](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/bluer-objects.svg)](https://pypi.org/project/bluer-objects/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/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.4.1`](https://github.com/kamangir/bluer-objects).
55
+ built by 🌀 [`blue_options-4.240.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌀 [`bluer_objects-6.6.1`](https://github.com/kamangir/bluer-objects).
56
56
 
57
57
  built by 🌀 [`blueness-3.96.1`](https://github.com/kamangir/blueness).
@@ -1,4 +1,4 @@
1
- bluer_objects/__init__.py,sha256=_Wzi-0eQsR0P_nmMr8eRxYbawZ_rDC3kR_IyaO8Y040,309
1
+ bluer_objects/__init__.py,sha256=LvR7JTIIYkkCheXWHypjU-TwbkNPTy0BYQVX97u1CEE,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
@@ -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.4.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
146
- bluer_objects-6.4.1.dist-info/METADATA,sha256=aBR7UyX_2sjNRL49eQ4iEdB_a9-E40az8o1uQWrwROI,2652
147
- bluer_objects-6.4.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
148
- bluer_objects-6.4.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
149
- bluer_objects-6.4.1.dist-info/RECORD,,
127
+ bluer_objects-6.6.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
128
+ bluer_objects-6.6.1.dist-info/METADATA,sha256=F4FQ7fWNnEScD6oCoFlKJ-zfEf72KkFcVyNqcd9onNg,2652
129
+ bluer_objects-6.6.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
130
+ bluer_objects-6.6.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
131
+ bluer_objects-6.6.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- from bluer_objects.mysql.cache.functions import (
2
- create,
3
- clone,
4
- read,
5
- write,
6
- search,
7
- search_value,
8
- )
@@ -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,9 +0,0 @@
1
- from bluer_objects.mysql.relations.functions import (
2
- clone,
3
- create,
4
- get,
5
- search,
6
- set_,
7
- inverse_of,
8
- list_of,
9
- )
@@ -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)
@@ -1,180 +0,0 @@
1
- import os
2
- from typing import Union, Dict, List
3
- from functools import reduce
4
-
5
- from bluer_objects import file
6
- from bluer_objects.mysql.table import Table
7
- from bluer_objects.logger import logger
8
-
9
-
10
- _, inverse_of = file.load_json(
11
- os.path.join(
12
- file.path(__file__),
13
- "relations.json",
14
- )
15
- )
16
- inverse_of.update({inverse_of[relation]: relation for relation in inverse_of})
17
- inverse_of[""] = ""
18
-
19
- list_of = sorted(list(set(list(inverse_of.keys()) + list(inverse_of.values()))))
20
-
21
-
22
- columns = "object_1,object_2,relation,timestamp".split(",")
23
-
24
-
25
- def clone(
26
- object_1: str,
27
- object_2: str,
28
- ) -> bool:
29
- return reduce(
30
- lambda x, y: x and y,
31
- [
32
- reduce(
33
- lambda x, y: x and y,
34
- [set_(object_2, object, relation) for object in object_list],
35
- True,
36
- )
37
- for relation, object_list in search(object_1).items()
38
- ],
39
- True,
40
- )
41
-
42
-
43
- def create() -> bool:
44
- return Table.Create(
45
- "relations",
46
- [
47
- "object_1 VARCHAR(256) NOT NULL",
48
- "object_2 VARCHAR(256) NOT NULL",
49
- "relation VARCHAR(256) NOT NULL",
50
- ],
51
- )
52
-
53
-
54
- def get(
55
- object_1: str,
56
- object_2: str,
57
- ) -> str:
58
- if object_1 > object_2:
59
- return inverse_of[get(object_1=object_2, object_2=object_1)]
60
-
61
- table = Table(name="relations")
62
-
63
- if not table.connect():
64
- return ""
65
-
66
- success, output = table.execute(
67
- "SELECT r.relation "
68
- "FROM abcli.relations r "
69
- "INNER JOIN ( "
70
- "SELECT MAX(timestamp) AS max_timestamp "
71
- "FROM abcli.relations "
72
- f'WHERE object_1="{object_1}" AND object_2="{object_2}" '
73
- ") rm "
74
- "ON r.timestamp=rm.max_timestamp "
75
- f'WHERE object_1="{object_1}" AND object_2="{object_2}";'
76
- )
77
- if not success:
78
- return ""
79
-
80
- if not table.disconnect():
81
- return ""
82
-
83
- return "" if not output else output[-1][0]
84
-
85
-
86
- def search(
87
- object: str,
88
- relation: str = "",
89
- count: int = -1,
90
- ) -> Union[
91
- Dict[str, List[str]],
92
- List[str],
93
- ]:
94
- table = Table(name="relations")
95
-
96
- output = [] if relation else {}
97
-
98
- if not table.connect():
99
- return output
100
-
101
- success, output_right = table.execute(
102
- "SELECT r.relation, r.object_2 "
103
- "FROM abcli.relations r "
104
- "INNER JOIN ( "
105
- "SELECT object_2, MAX(timestamp) AS max_timestamp "
106
- "FROM abcli.relations "
107
- f'WHERE object_1="{object}" GROUP BY object_2'
108
- ") rm "
109
- "ON r.timestamp=rm.max_timestamp "
110
- f'WHERE object_1="{object}"; '
111
- )
112
- if not success:
113
- return {}
114
-
115
- success, output_left = table.execute(
116
- "SELECT r.relation, r.object_1 "
117
- "FROM abcli.relations r "
118
- "INNER JOIN ( "
119
- "SELECT object_1, MAX(timestamp) AS max_timestamp "
120
- "FROM abcli.relations "
121
- f'WHERE object_2="{object}" GROUP BY object_1'
122
- ") rm "
123
- "ON r.timestamp=rm.max_timestamp "
124
- f'WHERE object_2="{object}"; '
125
- )
126
- if not success:
127
- return output
128
-
129
- if not table.disconnect():
130
- return output
131
-
132
- raw_output = {thing[1]: thing[0] for thing in output_right}
133
- raw_output.update({thing[1]: inverse_of[thing[0]] for thing in output_left})
134
-
135
- raw_output = {thing: relation for thing, relation in raw_output.items() if relation}
136
-
137
- output = {}
138
- for object_, relation_ in raw_output.items():
139
- output[relation_] = output.get(relation_, []) + [object_]
140
-
141
- if not relation:
142
- return output
143
-
144
- output = output.get(relation, [])
145
-
146
- if count != -1:
147
- output = output[-count:]
148
-
149
- return output
150
-
151
-
152
- def set_(
153
- object_1: str,
154
- object_2: str,
155
- relation: str,
156
- ) -> bool:
157
- if relation not in list_of:
158
- logger.error(f"-relations: set: {relation}: relation not found.")
159
- return False
160
-
161
- if object_1 > object_2:
162
- return set_(object_2, object_1, inverse_of[relation])
163
-
164
- table = Table(name="relations")
165
-
166
- if not table.connect():
167
- return False
168
-
169
- if not table.insert(
170
- ["object_1", "object_2", "relation"],
171
- [object_1, object_2, relation],
172
- ):
173
- return False
174
-
175
- if not table.disconnect():
176
- return False
177
-
178
- logger.info("{} ={}=> {}".format(object_1, relation if relation else "X", object_2))
179
-
180
- return True