osbot-utils 1.7.7__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.
- osbot_utils/__init__.py +1 -0
- osbot_utils/base_classes/Cache_Pickle.py +129 -0
- osbot_utils/base_classes/Kwargs_To_Disk.py +27 -0
- osbot_utils/base_classes/Kwargs_To_Self.py +308 -0
- osbot_utils/base_classes/Type_Safe__List.py +14 -0
- osbot_utils/base_classes/__init__.py +0 -0
- osbot_utils/context_managers/__init__.py +0 -0
- osbot_utils/context_managers/capture_duration.py +33 -0
- osbot_utils/decorators/__init__.py +0 -0
- osbot_utils/decorators/classes/__init__.py +0 -0
- osbot_utils/decorators/classes/singleton.py +9 -0
- osbot_utils/decorators/lists/__init__.py +0 -0
- osbot_utils/decorators/lists/filter_list.py +12 -0
- osbot_utils/decorators/lists/group_by.py +21 -0
- osbot_utils/decorators/lists/index_by.py +27 -0
- osbot_utils/decorators/methods/__init__.py +0 -0
- osbot_utils/decorators/methods/cache.py +19 -0
- osbot_utils/decorators/methods/cache_on_function.py +56 -0
- osbot_utils/decorators/methods/cache_on_self.py +78 -0
- osbot_utils/decorators/methods/cache_on_tmp.py +71 -0
- osbot_utils/decorators/methods/capture_exception.py +37 -0
- osbot_utils/decorators/methods/capture_status.py +20 -0
- osbot_utils/decorators/methods/catch.py +13 -0
- osbot_utils/decorators/methods/context.py +11 -0
- osbot_utils/decorators/methods/depreciated.py +79 -0
- osbot_utils/decorators/methods/function_type_check.py +62 -0
- osbot_utils/decorators/methods/obj_as_context.py +6 -0
- osbot_utils/decorators/methods/remove_return_value.py +22 -0
- osbot_utils/decorators/methods/required_fields.py +19 -0
- osbot_utils/fluent/Fluent_Dict.py +19 -0
- osbot_utils/fluent/Fluent_List.py +44 -0
- osbot_utils/fluent/__init__.py +1 -0
- osbot_utils/graphs/__init__.py +0 -0
- osbot_utils/graphs/mermaid/Mermaid.py +75 -0
- osbot_utils/graphs/mermaid/Mermaid__Edge.py +49 -0
- osbot_utils/graphs/mermaid/Mermaid__Graph.py +93 -0
- osbot_utils/graphs/mermaid/Mermaid__Node.py +69 -0
- osbot_utils/graphs/mermaid/Mermaid__Renderer.py +54 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Edge__Config.py +7 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Node__Config.py +9 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Render__Config.py +7 -0
- osbot_utils/graphs/mermaid/examples/Mermaid_Examples__FlowChart.py +98 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Diagram_Direction.py +9 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Diagram__Type.py +17 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Node__Shape.py +30 -0
- osbot_utils/graphs/mgraph/MGraph.py +53 -0
- osbot_utils/graphs/mgraph/MGraph__Config.py +7 -0
- osbot_utils/graphs/mgraph/MGraph__Data.py +139 -0
- osbot_utils/graphs/mgraph/MGraph__Edge.py +27 -0
- osbot_utils/graphs/mgraph/MGraph__Node.py +33 -0
- osbot_utils/graphs/mgraph/MGraph__Random_Graphs.py +27 -0
- osbot_utils/graphs/mgraph/MGraph__Serializer.py +43 -0
- osbot_utils/graphs/mgraph/MGraphs.py +17 -0
- osbot_utils/graphs/mgraph/__init__.py +0 -0
- osbot_utils/helpers/CPrint.py +98 -0
- osbot_utils/helpers/Dict_To_Attr.py +7 -0
- osbot_utils/helpers/Local_Cache.py +111 -0
- osbot_utils/helpers/Local_Caches.py +54 -0
- osbot_utils/helpers/Print_Table.py +369 -0
- osbot_utils/helpers/Python_Audit.py +45 -0
- osbot_utils/helpers/Random_Seed.py +27 -0
- osbot_utils/helpers/SCP.py +58 -0
- osbot_utils/helpers/SSH.py +151 -0
- osbot_utils/helpers/Type_Registry.py +16 -0
- osbot_utils/helpers/__init__.py +0 -0
- osbot_utils/helpers/ast/Ast.py +35 -0
- osbot_utils/helpers/ast/Ast_Base.py +124 -0
- osbot_utils/helpers/ast/Ast_Data.py +28 -0
- osbot_utils/helpers/ast/Ast_Load.py +62 -0
- osbot_utils/helpers/ast/Ast_Merge.py +26 -0
- osbot_utils/helpers/ast/Ast_Node.py +117 -0
- osbot_utils/helpers/ast/Ast_Visit.py +85 -0
- osbot_utils/helpers/ast/Call_Tree.py +38 -0
- osbot_utils/helpers/ast/__init__.py +145 -0
- osbot_utils/helpers/ast/nodes/Ast_Add.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Alias.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_And.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Argument.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Arguments.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Assert.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Assign.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Attribute.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Aug_Assign.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Bin_Op.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Bool_Op.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Break.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Call.py +17 -0
- osbot_utils/helpers/ast/nodes/Ast_Class_Def.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Compare.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Comprehension.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Constant.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Continue.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Dict.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Eq.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Except_Handler.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Expr.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_For.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Function_Def.py +17 -0
- osbot_utils/helpers/ast/nodes/Ast_Generator_Exp.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Gt.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_GtE.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_If.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_If_Exp.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Import.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Import_From.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_In.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Is.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Is_Not.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Keyword.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Lambda.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_List.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_List_Comp.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Load.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Lt.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_LtE.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Mod.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Module.py +20 -0
- osbot_utils/helpers/ast/nodes/Ast_Mult.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Name.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Not.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Not_Eq.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Not_In.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Or.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Pass.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Pow.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Raise.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Return.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Set.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Slice.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Starred.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Store.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Sub.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Subscript.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Try.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Tuple.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Unary_Op.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_While.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_With.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_With_Item.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Yield.py +7 -0
- osbot_utils/helpers/ast/nodes/__init__.py +0 -0
- osbot_utils/helpers/html/Dict_To_Css.py +20 -0
- osbot_utils/helpers/html/Dict_To_Html.py +59 -0
- osbot_utils/helpers/html/Dict_To_Tags.py +88 -0
- osbot_utils/helpers/html/Html_To_Dict.py +75 -0
- osbot_utils/helpers/html/Html_To_Tag.py +20 -0
- osbot_utils/helpers/html/Tag__Base.py +91 -0
- osbot_utils/helpers/html/Tag__Body.py +5 -0
- osbot_utils/helpers/html/Tag__Div.py +5 -0
- osbot_utils/helpers/html/Tag__H.py +9 -0
- osbot_utils/helpers/html/Tag__HR.py +5 -0
- osbot_utils/helpers/html/Tag__Head.py +32 -0
- osbot_utils/helpers/html/Tag__Html.py +42 -0
- osbot_utils/helpers/html/Tag__Link.py +17 -0
- osbot_utils/helpers/html/Tag__Style.py +25 -0
- osbot_utils/helpers/html/__init__.py +0 -0
- osbot_utils/helpers/pubsub/Event__Queue.py +95 -0
- osbot_utils/helpers/pubsub/PubSub__Client.py +53 -0
- osbot_utils/helpers/pubsub/PubSub__Room.py +13 -0
- osbot_utils/helpers/pubsub/PubSub__Server.py +94 -0
- osbot_utils/helpers/pubsub/PubSub__Sqlite.py +24 -0
- osbot_utils/helpers/pubsub/__init__.py +0 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event.py +15 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Connect.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Disconnect.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Join_Room.py +8 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Leave_Room.py +8 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Message.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__PubSub__Client.py +8 -0
- osbot_utils/helpers/pubsub/schemas/__init__.py +0 -0
- osbot_utils/helpers/sqlite/Capture_Sqlite_Error.py +51 -0
- osbot_utils/helpers/sqlite/Sqlite__Cursor.py +87 -0
- osbot_utils/helpers/sqlite/Sqlite__Database.py +137 -0
- osbot_utils/helpers/sqlite/Sqlite__Field.py +70 -0
- osbot_utils/helpers/sqlite/Sqlite__Globals.py +5 -0
- osbot_utils/helpers/sqlite/Sqlite__Table.py +293 -0
- osbot_utils/helpers/sqlite/Sqlite__Table__Create.py +96 -0
- osbot_utils/helpers/sqlite/Temp_Sqlite__Database__Disk.py +17 -0
- osbot_utils/helpers/sqlite/Temp_Sqlite__Table.py +23 -0
- osbot_utils/helpers/sqlite/__init__.py +0 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__Cache__Requests.py +214 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__Cache__Requests__Patch.py +63 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Files.py +23 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Graph.py +47 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Json.py +83 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Local.py +20 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Requests.py +39 -0
- osbot_utils/helpers/sqlite/domains/__init__.py +0 -0
- osbot_utils/helpers/sqlite/domains/schemas/Schema__Table__Requests.py +12 -0
- osbot_utils/helpers/sqlite/domains/schemas/__init__.py +0 -0
- osbot_utils/helpers/sqlite/models/Sqlite__Field__Type.py +37 -0
- osbot_utils/helpers/sqlite/models/__init__.py +0 -0
- osbot_utils/helpers/sqlite/sample_data/Sqlite__Sample_Data__Chinook.py +116 -0
- osbot_utils/helpers/sqlite/sample_data/__init__.py +0 -0
- osbot_utils/helpers/sqlite/sql_builder/SQL_Builder.py +159 -0
- osbot_utils/helpers/sqlite/sql_builder/SQL_Builder__Select.py +12 -0
- osbot_utils/helpers/sqlite/sql_builder/__init__.py +0 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Config.py +63 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Edges.py +46 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Files.py +45 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Nodes.py +52 -0
- osbot_utils/helpers/sqlite/tables/__init__.py +0 -0
- osbot_utils/helpers/trace/Trace_Call.py +120 -0
- osbot_utils/helpers/trace/Trace_Call__Config.py +94 -0
- osbot_utils/helpers/trace/Trace_Call__Graph.py +26 -0
- osbot_utils/helpers/trace/Trace_Call__Handler.py +215 -0
- osbot_utils/helpers/trace/Trace_Call__Print_Lines.py +85 -0
- osbot_utils/helpers/trace/Trace_Call__Print_Traces.py +170 -0
- osbot_utils/helpers/trace/Trace_Call__Stack.py +166 -0
- osbot_utils/helpers/trace/Trace_Call__Stack_Node.py +59 -0
- osbot_utils/helpers/trace/Trace_Call__Stats.py +71 -0
- osbot_utils/helpers/trace/Trace_Call__View_Model.py +75 -0
- osbot_utils/helpers/trace/Trace_Files.py +33 -0
- osbot_utils/helpers/trace/__init__.py +0 -0
- osbot_utils/testing/Catch.py +54 -0
- osbot_utils/testing/Duration.py +69 -0
- osbot_utils/testing/Hook_Method.py +118 -0
- osbot_utils/testing/Log_To_Queue.py +46 -0
- osbot_utils/testing/Log_To_String.py +37 -0
- osbot_utils/testing/Logging.py +81 -0
- osbot_utils/testing/Patch_Print.py +52 -0
- osbot_utils/testing/Profiler.py +89 -0
- osbot_utils/testing/Stderr.py +19 -0
- osbot_utils/testing/Stdout.py +19 -0
- osbot_utils/testing/Temp_File.py +46 -0
- osbot_utils/testing/Temp_Folder.py +114 -0
- osbot_utils/testing/Temp_Sys_Path.py +13 -0
- osbot_utils/testing/Temp_Web_Server.py +83 -0
- osbot_utils/testing/Temp_Zip.py +45 -0
- osbot_utils/testing/Temp_Zip_In_Memory.py +90 -0
- osbot_utils/testing/Unit_Test.py +34 -0
- osbot_utils/testing/Unzip_File.py +30 -0
- osbot_utils/testing/__init__.py +0 -0
- osbot_utils/utils/Assert.py +52 -0
- osbot_utils/utils/Call_Stack.py +187 -0
- osbot_utils/utils/Csv.py +32 -0
- osbot_utils/utils/Dev.py +47 -0
- osbot_utils/utils/Exceptions.py +7 -0
- osbot_utils/utils/Files.py +528 -0
- osbot_utils/utils/Functions.py +113 -0
- osbot_utils/utils/Http.py +136 -0
- osbot_utils/utils/Int.py +6 -0
- osbot_utils/utils/Json.py +171 -0
- osbot_utils/utils/Json_Cache.py +59 -0
- osbot_utils/utils/Lists.py +198 -0
- osbot_utils/utils/Misc.py +496 -0
- osbot_utils/utils/Objects.py +341 -0
- osbot_utils/utils/Png.py +29 -0
- osbot_utils/utils/Process.py +73 -0
- osbot_utils/utils/Python_Logger.py +301 -0
- osbot_utils/utils/Status.py +79 -0
- osbot_utils/utils/Str.py +63 -0
- osbot_utils/utils/Version.py +16 -0
- osbot_utils/utils/Zip.py +97 -0
- osbot_utils/utils/__init__.py +16 -0
- osbot_utils/version +1 -0
- osbot_utils-1.7.7.dist-info/LICENSE +201 -0
- osbot_utils-1.7.7.dist-info/METADATA +46 -0
- osbot_utils-1.7.7.dist-info/RECORD +260 -0
- osbot_utils-1.7.7.dist-info/WHEEL +4 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
2
|
+
from osbot_utils.graphs.mermaid.Mermaid__Node import LINE_PADDING, Mermaid__Node
|
3
|
+
from osbot_utils.graphs.mgraph.MGraph__Node import MGraph__Node
|
4
|
+
from osbot_utils.utils.Str import safe_str
|
5
|
+
|
6
|
+
|
7
|
+
class MGraph__Edge(Kwargs_To_Self):
|
8
|
+
attributes : dict
|
9
|
+
from_node : MGraph__Node
|
10
|
+
label : str
|
11
|
+
to_node : MGraph__Node
|
12
|
+
|
13
|
+
def __init__(self, **kwargs):
|
14
|
+
super().__init__(**kwargs)
|
15
|
+
|
16
|
+
# def __repr__(self):
|
17
|
+
# return self.__str__()
|
18
|
+
|
19
|
+
def __str__(self):
|
20
|
+
return f'[Graph Edge] from "{self.from_node.key}" to "{self.to_node.key}" '
|
21
|
+
|
22
|
+
# def cast(self, source):
|
23
|
+
# self.__dict__ = source.__dict__
|
24
|
+
# return self
|
25
|
+
|
26
|
+
def data(self):
|
27
|
+
return self.__locals__() # todo: see if there is a better way to do this (specialy as the edge objects gets more features and attributes)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from osbot_utils.utils.Misc import random_id
|
2
|
+
|
3
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
4
|
+
|
5
|
+
|
6
|
+
class MGraph__Node(Kwargs_To_Self):
|
7
|
+
attributes : dict
|
8
|
+
key : str
|
9
|
+
label : str
|
10
|
+
|
11
|
+
def __init__(self, **kwargs):
|
12
|
+
super().__init__(**kwargs)
|
13
|
+
if not self.key:
|
14
|
+
self.key = random_id()
|
15
|
+
if not self.label:
|
16
|
+
self.label = self.key
|
17
|
+
|
18
|
+
def __repr__(self):
|
19
|
+
return self.__str__()
|
20
|
+
|
21
|
+
def __str__(self):
|
22
|
+
return f'[Graph Node] {self.key}'
|
23
|
+
|
24
|
+
def data(self):
|
25
|
+
return self.__locals__() # todo: see if there is a better way to do this (specialy as the node objects gets more features and attributes)
|
26
|
+
|
27
|
+
def set_key(self, value: str):
|
28
|
+
self.key = value
|
29
|
+
return self
|
30
|
+
|
31
|
+
def set_label(self, value: str):
|
32
|
+
self.label = value
|
33
|
+
return self
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
2
|
+
|
3
|
+
from osbot_utils.graphs.mgraph.MGraph import MGraph
|
4
|
+
from osbot_utils.graphs.mgraph.MGraph__Config import MGraph__Config
|
5
|
+
from osbot_utils.utils.Misc import random_int
|
6
|
+
|
7
|
+
|
8
|
+
class MGraph__Random_Graphs(Kwargs_To_Self):
|
9
|
+
config : MGraph__Config
|
10
|
+
graph_key : str
|
11
|
+
|
12
|
+
def new_graph(self):
|
13
|
+
return MGraph(config=self.config, key=self.graph_key)
|
14
|
+
|
15
|
+
def with_x_nodes_and_y_edges(self, x=10, y=20):
|
16
|
+
MGraph = self.new_graph()
|
17
|
+
if x >0 and y > 0 :
|
18
|
+
for i in range(x):
|
19
|
+
MGraph.add_node(label=f'node_{i}')
|
20
|
+
for i in range(y):
|
21
|
+
from_node_id = random_int(max=x) - 1
|
22
|
+
to_node_id = random_int(max=x) - 1
|
23
|
+
from_node = MGraph.nodes[from_node_id]
|
24
|
+
to_node = MGraph.nodes[to_node_id ]
|
25
|
+
MGraph.add_edge(from_node=from_node, to_node=to_node)
|
26
|
+
|
27
|
+
return MGraph
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from enum import Enum, auto
|
2
|
+
from osbot_utils.utils.Str import safe_str
|
3
|
+
from osbot_utils.helpers.Local_Cache import Local_Cache
|
4
|
+
|
5
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
6
|
+
from osbot_utils.graphs.mgraph.MGraph import MGraph
|
7
|
+
|
8
|
+
|
9
|
+
class Serialization_Mode(Enum):
|
10
|
+
JSON = auto()
|
11
|
+
PICKLE = auto()
|
12
|
+
|
13
|
+
class MGraph__Serializer(Kwargs_To_Self):
|
14
|
+
|
15
|
+
caches_name : str = 'mgraph_tests'
|
16
|
+
mode : Serialization_Mode = Serialization_Mode.PICKLE
|
17
|
+
|
18
|
+
local_cache : Local_Cache # todo, refactor this into an MGraph__Storage__Disk class
|
19
|
+
key : str
|
20
|
+
mgraph : MGraph
|
21
|
+
|
22
|
+
def __init__(self, **kwargs):
|
23
|
+
super().__init__(**kwargs)
|
24
|
+
self.key = safe_str(f'serialiser_for__{self.mgraph.key}')
|
25
|
+
|
26
|
+
self.local_cache = Local_Cache(cache_name=self.key, caches_name=self.caches_name)
|
27
|
+
|
28
|
+
|
29
|
+
def save(self):
|
30
|
+
if self.mode == Serialization_Mode.JSON:
|
31
|
+
return self.save_to_json()
|
32
|
+
if self.mode == Serialization_Mode.PICKLE:
|
33
|
+
return self.save_to_pickle()
|
34
|
+
|
35
|
+
def save_to_json(self):
|
36
|
+
graph_data = self.mgraph.data().graph_data()
|
37
|
+
#pprint(graph_data)
|
38
|
+
self.local_cache.set('graph_data', graph_data)
|
39
|
+
return True
|
40
|
+
|
41
|
+
def save_to_pickle(self):
|
42
|
+
#obj_info(self.local_cache)
|
43
|
+
return '...pickle save - to be implemented...'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import random
|
2
|
+
|
3
|
+
from osbot_utils.utils.Files import file_exists, file_extension, pickle_load_from_file
|
4
|
+
|
5
|
+
from osbot_utils.graphs.mgraph.MGraph__Random_Graphs import MGraph__Random_Graphs
|
6
|
+
|
7
|
+
|
8
|
+
class MGraphs:
|
9
|
+
|
10
|
+
def new__random(self, config=None, graph_key=None, x_nodes=10, y_edges=20):
|
11
|
+
return MGraph__Random_Graphs(config=config, graph_key=graph_key).with_x_nodes_and_y_edges(x=x_nodes, y=y_edges)
|
12
|
+
|
13
|
+
# todo : implement based on multiple save a load methods
|
14
|
+
# def load(self, file_path):
|
15
|
+
# if file_exists(file_path):
|
16
|
+
# if file_extension(file_path):
|
17
|
+
# return pickle_load_from_file(file_path)
|
File without changes
|
@@ -0,0 +1,98 @@
|
|
1
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
2
|
+
|
3
|
+
|
4
|
+
# note these attributes will be replaced by methods by CPrint. This is done like this in order to:
|
5
|
+
# - Have code complete on CPrint
|
6
|
+
# - not have the write the code for each of the methods
|
7
|
+
# - have a good and logical place to capture the ID of the color
|
8
|
+
|
9
|
+
class Colors:
|
10
|
+
black = "30"
|
11
|
+
blue = "34"
|
12
|
+
cyan = "36"
|
13
|
+
grey = "38;5;15"
|
14
|
+
green = "32"
|
15
|
+
none = "0"
|
16
|
+
magenta = "35"
|
17
|
+
red = "31"
|
18
|
+
white = "38;5;15"
|
19
|
+
yellow = "33"
|
20
|
+
bright_black = "90"
|
21
|
+
bright_red = "91"
|
22
|
+
bright_green = "92"
|
23
|
+
bright_yellow = "93"
|
24
|
+
bright_blue = "94"
|
25
|
+
bright_magenta = "95"
|
26
|
+
bright_cyan = "96"
|
27
|
+
bright_white = "97"
|
28
|
+
dark_red = "38;5;124" # see https://github.com/fidian/ansi for a full list
|
29
|
+
|
30
|
+
|
31
|
+
class CPrint(Colors, Kwargs_To_Self):
|
32
|
+
apply_colors : bool = True
|
33
|
+
auto_new_line : bool = True
|
34
|
+
auto_print : bool = True
|
35
|
+
clear_on_print : bool = True
|
36
|
+
current_line : str
|
37
|
+
lines : list
|
38
|
+
|
39
|
+
def __getattribute__(self, name): # this will replace the attributes defined in colors with methods that will call add_to_current_line with the params provided
|
40
|
+
if name != '__getattribute__' and hasattr(Colors, name): # if name is one of the colors defined in Colors
|
41
|
+
def method(*args, **kwargs): # create a method to replace the attribute
|
42
|
+
return self.add_with_color(name, *args, **kwargs) # pass the data to add_with_color
|
43
|
+
return method
|
44
|
+
return super().__getattribute__(name) # if the attribute name is not one of the attributes defined in colors, restore the normal behaviour of __getattribute__
|
45
|
+
|
46
|
+
def add_with_color(self, color_name, *args, **kwargs):
|
47
|
+
color_code = getattr(Colors, color_name) # capture the color from the Colors class
|
48
|
+
self.add_to_current_line(color_code, *args, **kwargs) # add the color code to the current line
|
49
|
+
return self
|
50
|
+
|
51
|
+
def add_to_current_line(self, color_code, *args, **kwargs):
|
52
|
+
args = [str(arg) for arg in args] # Convert all non-string arguments to strings
|
53
|
+
text = "".join(args) # Concatenate all arguments without a space (to have beter support for multi-prints per line)
|
54
|
+
if self.apply_colors:
|
55
|
+
color_start = f"\033[{color_code}m" # ANSI color code start and end
|
56
|
+
color_end = "\033[0m"
|
57
|
+
kwargs['end'] = '' # remove the default print end (which is \n)
|
58
|
+
|
59
|
+
text_with_colors = f"{color_start}{text}{color_end}"
|
60
|
+
self.current_line += text_with_colors
|
61
|
+
else:
|
62
|
+
self.current_line += text
|
63
|
+
self.apply_config_options()
|
64
|
+
return self
|
65
|
+
|
66
|
+
def apply_config_options(self):
|
67
|
+
if self.auto_new_line:
|
68
|
+
self.flush()
|
69
|
+
if self.auto_print:
|
70
|
+
self.print()
|
71
|
+
|
72
|
+
def flush(self):
|
73
|
+
if self.current_line:
|
74
|
+
self.lines.append(self.current_line)
|
75
|
+
self.current_line = ''
|
76
|
+
return self
|
77
|
+
|
78
|
+
def lines_str(self):
|
79
|
+
lines_str = ''
|
80
|
+
for line in self.lines:
|
81
|
+
lines_str += line + '\n'
|
82
|
+
return lines_str
|
83
|
+
|
84
|
+
def new_line(self):
|
85
|
+
self.flush()
|
86
|
+
self.lines.append('')
|
87
|
+
self.apply_config_options()
|
88
|
+
return self
|
89
|
+
|
90
|
+
def print(self):
|
91
|
+
self.flush()
|
92
|
+
for line in self.lines:
|
93
|
+
print(line)
|
94
|
+
if self.clear_on_print:
|
95
|
+
self.lines = []
|
96
|
+
return self
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
from osbot_utils.utils.Misc import list_set
|
2
|
+
from osbot_utils.utils.Dev import pprint
|
3
|
+
from osbot_utils.decorators.methods.cache_on_self import cache_on_self
|
4
|
+
from osbot_utils.utils.Files import current_temp_folder, path_combine, create_folder, safe_file_name, file_exists, file_delete
|
5
|
+
from osbot_utils.utils.Json import json_save_file, json_load_file
|
6
|
+
|
7
|
+
|
8
|
+
class Local_Cache:
|
9
|
+
|
10
|
+
DEFAULT_CACHES_NAME = "_cache_data"
|
11
|
+
|
12
|
+
def __init__(self, cache_name, caches_name=None):
|
13
|
+
self.caches_name = caches_name or Local_Cache.DEFAULT_CACHES_NAME
|
14
|
+
self.cache_name = safe_file_name(cache_name)
|
15
|
+
self._data = None
|
16
|
+
|
17
|
+
def add(self, key, value):
|
18
|
+
self.data()[key] = value
|
19
|
+
self.save()
|
20
|
+
return self
|
21
|
+
|
22
|
+
def add_data(self, items):
|
23
|
+
data = self.data()
|
24
|
+
for key, value in items.items():
|
25
|
+
data[key] = value
|
26
|
+
self.save()
|
27
|
+
return self
|
28
|
+
|
29
|
+
def cache_delete(self):
|
30
|
+
return file_delete(self.path_cache_file())
|
31
|
+
|
32
|
+
def cache_exists(self):
|
33
|
+
return file_exists(self.path_cache_file())
|
34
|
+
|
35
|
+
def create(self):
|
36
|
+
if not self.cache_exists():
|
37
|
+
self.save()
|
38
|
+
return self
|
39
|
+
|
40
|
+
def has_key(self, key):
|
41
|
+
return key in self.keys()
|
42
|
+
|
43
|
+
def save(self):
|
44
|
+
data = self.data() or {}
|
45
|
+
json_save_file(data, self.path_cache_file())
|
46
|
+
return self
|
47
|
+
|
48
|
+
def data(self):
|
49
|
+
if self._data is None:
|
50
|
+
self._data = json_load_file(self.path_cache_file())
|
51
|
+
return self._data
|
52
|
+
|
53
|
+
def get(self, key, default_value=None):
|
54
|
+
return self.data().get(key, default_value)
|
55
|
+
|
56
|
+
def info(self):
|
57
|
+
return { 'caches_name' : self.caches_name ,
|
58
|
+
'cache_name' : self.cache_name ,
|
59
|
+
'path_cache_file': self.path_cache_file() ,
|
60
|
+
'data_keys' : list_set(self.data()) }
|
61
|
+
|
62
|
+
def name(self):
|
63
|
+
return self.cache_name
|
64
|
+
|
65
|
+
def print_info(self):
|
66
|
+
pprint(self.info())
|
67
|
+
|
68
|
+
def keys(self):
|
69
|
+
return self.data().keys()
|
70
|
+
|
71
|
+
@cache_on_self
|
72
|
+
def path_root_folder(self):
|
73
|
+
path_root_folder = path_combine(current_temp_folder(), self.caches_name)
|
74
|
+
create_folder(path_root_folder) # create if it doesn't exist
|
75
|
+
return path_root_folder
|
76
|
+
|
77
|
+
@cache_on_self
|
78
|
+
def path_cache_file(self):
|
79
|
+
return path_combine(self.path_root_folder(), f"{self.cache_name}.json")
|
80
|
+
|
81
|
+
def set(self, key, value):
|
82
|
+
return self.add(key, value)
|
83
|
+
|
84
|
+
def set_data(self,items):
|
85
|
+
return self.add_data(items)
|
86
|
+
|
87
|
+
def set_all_data(self, data):
|
88
|
+
self._data = data
|
89
|
+
self.save()
|
90
|
+
return self
|
91
|
+
|
92
|
+
def setup(self):
|
93
|
+
self.create()
|
94
|
+
return self
|
95
|
+
|
96
|
+
def remove(self, key):
|
97
|
+
if key in self.keys():
|
98
|
+
del self.data()[key]
|
99
|
+
self.save()
|
100
|
+
return True
|
101
|
+
return False
|
102
|
+
|
103
|
+
def values(self):
|
104
|
+
return self.data().values()
|
105
|
+
|
106
|
+
def __repr__(self):
|
107
|
+
return f"Local_Cache: {self.cache_name}"
|
108
|
+
|
109
|
+
# extra methods alias
|
110
|
+
|
111
|
+
#add = set
|
@@ -0,0 +1,54 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
from typing import Dict, List
|
3
|
+
from osbot_utils.helpers.Local_Cache import Local_Cache
|
4
|
+
from osbot_utils.utils.Files import current_temp_folder, path_combine,folder_exists, folder_delete
|
5
|
+
from osbot_utils.utils.Misc import random_text
|
6
|
+
|
7
|
+
|
8
|
+
class Local_Caches:
|
9
|
+
|
10
|
+
DEFAULT_NAME = "_cache_data" # todo: see if this is still being used
|
11
|
+
|
12
|
+
def __init__(self, caches_name=None):
|
13
|
+
self.caches_name = caches_name or random_text("local_caches")
|
14
|
+
|
15
|
+
def caches(self) -> Dict[str, Local_Cache]:
|
16
|
+
cache_names = self.existing_cache_names()
|
17
|
+
caches = {}
|
18
|
+
for cache_name in cache_names:
|
19
|
+
caches[cache_name] = self.cache(cache_name)
|
20
|
+
return caches
|
21
|
+
|
22
|
+
def delete(self) -> bool:
|
23
|
+
for cache_name, cache in self.caches().items():
|
24
|
+
cache.cache_delete()
|
25
|
+
return folder_delete(self.path_local_caches())
|
26
|
+
|
27
|
+
#
|
28
|
+
#@cache_on_self
|
29
|
+
def cache(self, cache_name) -> Local_Cache:
|
30
|
+
local_cache = Local_Cache(cache_name=cache_name, caches_name=self.caches_name)
|
31
|
+
local_cache.setup()
|
32
|
+
return local_cache
|
33
|
+
|
34
|
+
def exists(self) -> bool:
|
35
|
+
return folder_exists(self.path_local_caches())
|
36
|
+
|
37
|
+
def empty(self) -> bool:
|
38
|
+
return len(self.caches()) == 0
|
39
|
+
|
40
|
+
def existing_cache_names(self) -> List[str]:
|
41
|
+
cache_names = []
|
42
|
+
for f in self.path_local_caches().iterdir():
|
43
|
+
if f.is_file():
|
44
|
+
cache_name = f.name.replace('.json', '')
|
45
|
+
cache_names.append(cache_name)
|
46
|
+
return cache_names
|
47
|
+
|
48
|
+
#@cache_on_self
|
49
|
+
def path_local_caches(self) -> Path:
|
50
|
+
return Path(path_combine(current_temp_folder(), self.caches_name))
|
51
|
+
|
52
|
+
def setup(self):
|
53
|
+
self.path_local_caches().mkdir(parents=True, exist_ok=True)
|
54
|
+
return self
|