appier 1.31.4__py2.py3-none-any.whl → 1.32.0__py2.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.
- appier/__init__.py +333 -52
- appier/amqp.py +29 -30
- appier/api.py +214 -212
- appier/asgi.py +54 -55
- appier/async_neo.py +46 -35
- appier/async_old.py +55 -42
- appier/asynchronous.py +7 -13
- appier/base.py +1762 -1429
- appier/bus.py +51 -52
- appier/cache.py +99 -84
- appier/common.py +9 -11
- appier/component.py +17 -19
- appier/compress.py +25 -28
- appier/config.py +96 -73
- appier/controller.py +9 -15
- appier/crypt.py +25 -21
- appier/data.py +73 -57
- appier/defines.py +191 -226
- appier/exceptions.py +103 -63
- appier/execution.py +94 -88
- appier/export.py +90 -88
- appier/extra.py +6 -13
- appier/extra_neo.py +8 -11
- appier/extra_old.py +18 -16
- appier/geo.py +57 -47
- appier/git.py +101 -90
- appier/graph.py +23 -24
- appier/http.py +520 -398
- appier/legacy.py +373 -180
- appier/log.py +90 -97
- appier/meta.py +42 -42
- appier/mock.py +32 -34
- appier/model.py +793 -681
- appier/model_a.py +208 -183
- appier/mongo.py +183 -107
- appier/observer.py +39 -31
- appier/part.py +23 -24
- appier/preferences.py +44 -47
- appier/queuing.py +78 -96
- appier/redisdb.py +40 -35
- appier/request.py +227 -175
- appier/scheduler.py +13 -18
- appier/serialize.py +37 -31
- appier/session.py +161 -147
- appier/settings.py +2 -11
- appier/smtp.py +53 -49
- appier/storage.py +39 -33
- appier/structures.py +50 -45
- appier/test/__init__.py +2 -11
- appier/test/base.py +111 -108
- appier/test/cache.py +28 -35
- appier/test/config.py +10 -19
- appier/test/crypt.py +3 -12
- appier/test/data.py +3 -12
- appier/test/exceptions.py +8 -17
- appier/test/export.py +16 -33
- appier/test/graph.py +27 -60
- appier/test/http.py +42 -54
- appier/test/legacy.py +20 -30
- appier/test/log.py +14 -35
- appier/test/mock.py +27 -123
- appier/test/model.py +79 -91
- appier/test/part.py +5 -14
- appier/test/preferences.py +5 -13
- appier/test/queuing.py +29 -37
- appier/test/request.py +61 -73
- appier/test/serialize.py +12 -23
- appier/test/session.py +10 -19
- appier/test/smtp.py +8 -14
- appier/test/structures.py +20 -24
- appier/test/typesf.py +14 -28
- appier/test/util.py +480 -438
- appier/typesf.py +251 -171
- appier/util.py +578 -407
- appier/validation.py +280 -143
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
- appier-1.32.0.dist-info/RECORD +86 -0
- appier-1.31.4.dist-info/RECORD +0 -86
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/git.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -42,214 +33,234 @@ from . import common
|
|
|
42
33
|
from . import legacy
|
|
43
34
|
from . import exceptions
|
|
44
35
|
|
|
45
|
-
class Git(object):
|
|
46
36
|
|
|
37
|
+
class Git(object):
|
|
47
38
|
@classmethod
|
|
48
|
-
def is_git(cls, path
|
|
39
|
+
def is_git(cls, path=None):
|
|
49
40
|
path = path or common.base().get_base_path()
|
|
50
|
-
try:
|
|
51
|
-
|
|
41
|
+
try:
|
|
42
|
+
result = util.execute(["git", "status"], path=path)
|
|
43
|
+
except OSError:
|
|
44
|
+
return False
|
|
52
45
|
code = result["code"]
|
|
53
46
|
return code == 0
|
|
54
47
|
|
|
55
48
|
@classmethod
|
|
56
|
-
def clone(cls, url, path
|
|
49
|
+
def clone(cls, url, path=None, raise_e=True):
|
|
57
50
|
path = path or common.base().get_base_path()
|
|
58
|
-
result = util.execute(["git", "clone", url], path
|
|
59
|
-
if cls._wrap_error(result, raise_e
|
|
51
|
+
result = util.execute(["git", "clone", url], path=path)
|
|
52
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
53
|
+
return None
|
|
60
54
|
message = result.get("stdout", "")
|
|
61
55
|
return message
|
|
62
56
|
|
|
63
57
|
@classmethod
|
|
64
|
-
def fetch(cls, flags
|
|
58
|
+
def fetch(cls, flags=[], path=None, raise_e=True):
|
|
65
59
|
path = path or common.base().get_base_path()
|
|
66
|
-
result = util.execute(["git", "fetch"] + flags, path
|
|
67
|
-
if cls._wrap_error(result, raise_e
|
|
60
|
+
result = util.execute(["git", "fetch"] + flags, path=path)
|
|
61
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
62
|
+
return None
|
|
68
63
|
message = result.get("stdout", "")
|
|
69
64
|
return message
|
|
70
65
|
|
|
71
66
|
@classmethod
|
|
72
|
-
def pull(cls, flags
|
|
67
|
+
def pull(cls, flags=[], path=None, raise_e=True):
|
|
73
68
|
path = path or common.base().get_base_path()
|
|
74
|
-
result = util.execute(["git", "pull"] + flags, path
|
|
75
|
-
if cls._wrap_error(result, raise_e
|
|
69
|
+
result = util.execute(["git", "pull"] + flags, path=path)
|
|
70
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
71
|
+
return None
|
|
76
72
|
message = result.get("stdout", "")
|
|
77
73
|
return message
|
|
78
74
|
|
|
79
75
|
@classmethod
|
|
80
|
-
def push(cls, flags
|
|
76
|
+
def push(cls, flags=[], path=None, raise_e=True):
|
|
81
77
|
path = path or common.base().get_base_path()
|
|
82
|
-
result = util.execute(["git", "push"] + flags, path
|
|
83
|
-
if cls._wrap_error(result, raise_e
|
|
78
|
+
result = util.execute(["git", "push"] + flags, path=path)
|
|
79
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
80
|
+
return None
|
|
84
81
|
message = result.get("stdout", "")
|
|
85
82
|
return message
|
|
86
83
|
|
|
87
84
|
@classmethod
|
|
88
|
-
def commit(cls, message
|
|
85
|
+
def commit(cls, message="Update", flags=[], path=None, raise_e=True):
|
|
89
86
|
path = path or common.base().get_base_path()
|
|
90
|
-
result = util.execute(["git", "commit", "-m", message] + flags, path
|
|
91
|
-
if cls._wrap_error(result, raise_e
|
|
87
|
+
result = util.execute(["git", "commit", "-m", message] + flags, path=path)
|
|
88
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
89
|
+
return None
|
|
92
90
|
message = result.get("stdout", "")
|
|
93
91
|
return message
|
|
94
92
|
|
|
95
93
|
@classmethod
|
|
96
|
-
def checkout(cls, branch
|
|
94
|
+
def checkout(cls, branch="master", flags=[], path=None, raise_e=True):
|
|
97
95
|
path = path or common.base().get_base_path()
|
|
98
|
-
result = util.execute(["git", "checkout", branch] + flags, path
|
|
99
|
-
if cls._wrap_error(result, raise_e
|
|
96
|
+
result = util.execute(["git", "checkout", branch] + flags, path=path)
|
|
97
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
98
|
+
return None
|
|
100
99
|
message = result.get("stdout", "")
|
|
101
100
|
return message
|
|
102
101
|
|
|
103
102
|
@classmethod
|
|
104
|
-
def add(cls, target
|
|
103
|
+
def add(cls, target="*", flags=[], path=None, raise_e=True):
|
|
105
104
|
path = path or common.base().get_base_path()
|
|
106
|
-
result = util.execute(["git", "add", target] + flags, path
|
|
107
|
-
if cls._wrap_error(result, raise_e
|
|
105
|
+
result = util.execute(["git", "add", target] + flags, path=path)
|
|
106
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
107
|
+
return None
|
|
108
108
|
message = result.get("stdout", "")
|
|
109
109
|
return message
|
|
110
110
|
|
|
111
111
|
@classmethod
|
|
112
|
-
def add_upstream(cls, url, name
|
|
112
|
+
def add_upstream(cls, url, name="upstream", path=None, raise_e=True):
|
|
113
113
|
path = path or common.base().get_base_path()
|
|
114
|
-
result = util.execute(["git", "remote", "add", name, url], path
|
|
115
|
-
if cls._wrap_error(result, raise_e
|
|
114
|
+
result = util.execute(["git", "remote", "add", name, url], path=path)
|
|
115
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
116
|
+
return None
|
|
116
117
|
message = result.get("stdout", "")
|
|
117
118
|
return message
|
|
118
119
|
|
|
119
120
|
@classmethod
|
|
120
|
-
def remove_upstream(cls, name
|
|
121
|
+
def remove_upstream(cls, name="upstream", path=None, raise_e=True):
|
|
121
122
|
path = path or common.base().get_base_path()
|
|
122
|
-
result = util.execute(["git", "remote", "remove", name], path
|
|
123
|
-
if cls._wrap_error(result, raise_e
|
|
123
|
+
result = util.execute(["git", "remote", "remove", name], path=path)
|
|
124
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
125
|
+
return None
|
|
124
126
|
message = result.get("stdout", "")
|
|
125
127
|
return message
|
|
126
128
|
|
|
127
129
|
@classmethod
|
|
128
|
-
def config(cls, key, value, _global
|
|
130
|
+
def config(cls, key, value, _global=True, path=None, raise_e=True):
|
|
129
131
|
path = path or common.base().get_base_path()
|
|
130
132
|
result = util.execute(
|
|
131
|
-
["git", "config", "--global" if _global else "", key, value],
|
|
132
|
-
path = path
|
|
133
|
+
["git", "config", "--global" if _global else "", key, value], path=path
|
|
133
134
|
)
|
|
134
|
-
if cls._wrap_error(result, raise_e
|
|
135
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
136
|
+
return None
|
|
135
137
|
message = result.get("stdout", "")
|
|
136
138
|
return message
|
|
137
139
|
|
|
138
140
|
@classmethod
|
|
139
|
-
def get_config(cls, key, _global
|
|
141
|
+
def get_config(cls, key, _global=True, path=None, raise_e=False):
|
|
140
142
|
path = path or common.base().get_base_path()
|
|
141
143
|
result = util.execute(
|
|
142
|
-
["git", "config", "--global" if _global else "", "--get", key],
|
|
143
|
-
path = path
|
|
144
|
+
["git", "config", "--global" if _global else "", "--get", key], path=path
|
|
144
145
|
)
|
|
145
|
-
if cls._wrap_error(result, raise_e
|
|
146
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
147
|
+
return None
|
|
146
148
|
message = result.get("stdout", "")
|
|
147
149
|
value = message.strip()
|
|
148
150
|
return value
|
|
149
151
|
|
|
150
152
|
@classmethod
|
|
151
|
-
def get_branches(cls, names
|
|
153
|
+
def get_branches(cls, names=False, path=None, raise_e=False):
|
|
152
154
|
path = path or common.base().get_base_path()
|
|
153
|
-
result = util.execute(["git", "branch"], path
|
|
154
|
-
if cls._wrap_error(result, raise_e
|
|
155
|
+
result = util.execute(["git", "branch"], path=path)
|
|
156
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
157
|
+
return None
|
|
155
158
|
message = result.get("stdout", "")
|
|
156
159
|
branches = message.strip()
|
|
157
160
|
branches = branches.split("\n")
|
|
158
161
|
branches = [(value.lstrip("* "), value.startswith("*")) for value in branches]
|
|
159
|
-
if names:
|
|
162
|
+
if names:
|
|
163
|
+
branches = [branch[0] for branch in branches]
|
|
160
164
|
return branches
|
|
161
165
|
|
|
162
166
|
@classmethod
|
|
163
|
-
def get_branch(cls, path
|
|
167
|
+
def get_branch(cls, path=None, raise_e=False):
|
|
164
168
|
path = path or common.base().get_base_path()
|
|
165
|
-
branches = cls.get_branches(path
|
|
169
|
+
branches = cls.get_branches(path=path, raise_e=raise_e)
|
|
166
170
|
for branch, selected in branches:
|
|
167
|
-
if not selected:
|
|
171
|
+
if not selected:
|
|
172
|
+
continue
|
|
168
173
|
return branch
|
|
169
174
|
return None
|
|
170
175
|
|
|
171
176
|
@classmethod
|
|
172
|
-
def get_commit(cls, path
|
|
177
|
+
def get_commit(cls, path=None, raise_e=False):
|
|
173
178
|
path = path or common.base().get_base_path()
|
|
174
|
-
result = util.execute(["git", "rev-parse", "HEAD"], path
|
|
175
|
-
if cls._wrap_error(result, raise_e
|
|
179
|
+
result = util.execute(["git", "rev-parse", "HEAD"], path=path)
|
|
180
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
181
|
+
return None
|
|
176
182
|
message = result.get("stdout", "")
|
|
177
183
|
commit = message.strip()
|
|
178
184
|
return commit
|
|
179
185
|
|
|
180
186
|
@classmethod
|
|
181
|
-
def get_origin(cls, path
|
|
187
|
+
def get_origin(cls, path=None, raise_e=False):
|
|
182
188
|
path = path or common.base().get_base_path()
|
|
183
189
|
result = util.execute(
|
|
184
|
-
["git", "config", "--get", "remote.origin.url"],
|
|
185
|
-
path = path
|
|
190
|
+
["git", "config", "--get", "remote.origin.url"], path=path
|
|
186
191
|
)
|
|
187
|
-
if cls._wrap_error(result, raise_e
|
|
192
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
193
|
+
return None
|
|
188
194
|
message = result.get("stdout", "")
|
|
189
195
|
origin = message.strip()
|
|
190
196
|
origin = cls.safe_origin(origin)
|
|
191
197
|
return origin
|
|
192
198
|
|
|
193
199
|
@classmethod
|
|
194
|
-
def get_repo_path(cls, path
|
|
200
|
+
def get_repo_path(cls, path=None, raise_e=False):
|
|
195
201
|
path = path or common.base().get_base_path()
|
|
196
|
-
result = util.execute(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
)
|
|
200
|
-
if cls._wrap_error(result, raise_e = raise_e): return None
|
|
202
|
+
result = util.execute(["git", "rev-parse", "--show-toplevel"], path=path)
|
|
203
|
+
if cls._wrap_error(result, raise_e=raise_e):
|
|
204
|
+
return None
|
|
201
205
|
message = result.get("stdout", "")
|
|
202
206
|
repo_path = message.strip()
|
|
203
207
|
return repo_path
|
|
204
208
|
|
|
205
209
|
@classmethod
|
|
206
|
-
def safe_origin(cls, origin, display_l
|
|
210
|
+
def safe_origin(cls, origin, display_l=3):
|
|
207
211
|
parse = legacy.urlparse(origin)
|
|
208
212
|
safe_l = []
|
|
209
|
-
if parse.scheme:
|
|
210
|
-
|
|
213
|
+
if parse.scheme:
|
|
214
|
+
safe_l.append(parse.scheme + "://")
|
|
215
|
+
if parse.username:
|
|
216
|
+
safe_l.append(parse.username)
|
|
211
217
|
if parse.password:
|
|
212
218
|
obfuscated = util.obfuscate(parse.password)
|
|
213
219
|
safe_l.append(":" + obfuscated)
|
|
214
|
-
if parse.username:
|
|
215
|
-
|
|
216
|
-
if parse.
|
|
220
|
+
if parse.username:
|
|
221
|
+
safe_l.append("@")
|
|
222
|
+
if parse.hostname:
|
|
223
|
+
safe_l.append(parse.hostname)
|
|
224
|
+
if parse.path:
|
|
225
|
+
safe_l.append(parse.path)
|
|
217
226
|
return "".join(safe_l)
|
|
218
227
|
|
|
219
228
|
@classmethod
|
|
220
|
-
def norm_origin(cls, origin, prefix
|
|
221
|
-
if origin.startswith(("http://", "https://")):
|
|
222
|
-
|
|
229
|
+
def norm_origin(cls, origin, prefix="https://"):
|
|
230
|
+
if origin.startswith(("http://", "https://")):
|
|
231
|
+
return origin
|
|
232
|
+
if origin.endswith(".git"):
|
|
233
|
+
origin = origin[:-4]
|
|
223
234
|
origin = origin.replace(":", "/")
|
|
224
235
|
origin = prefix + origin
|
|
225
236
|
return origin
|
|
226
237
|
|
|
227
238
|
@classmethod
|
|
228
|
-
def parse_origin(cls, origin, safe
|
|
239
|
+
def parse_origin(cls, origin, safe=True):
|
|
229
240
|
parse = legacy.urlparse(origin)
|
|
230
241
|
if safe and not parse.scheme:
|
|
231
242
|
origin = cls.norm_origin(origin)
|
|
232
|
-
return cls.parse_origin(origin, safe
|
|
243
|
+
return cls.parse_origin(origin, safe=False)
|
|
233
244
|
scheme = parse.scheme if parse.scheme else "ssh"
|
|
234
245
|
username = parse.username if parse.username else None
|
|
235
246
|
password = parse.password if parse.password else None
|
|
236
247
|
hostname = parse.hostname if parse.hostname else None
|
|
237
248
|
path = parse.path if parse.path else None
|
|
238
249
|
return dict(
|
|
239
|
-
scheme
|
|
240
|
-
username
|
|
241
|
-
password
|
|
242
|
-
hostname
|
|
243
|
-
path
|
|
250
|
+
scheme=scheme,
|
|
251
|
+
username=username,
|
|
252
|
+
password=password,
|
|
253
|
+
hostname=hostname,
|
|
254
|
+
path=path,
|
|
244
255
|
)
|
|
245
256
|
|
|
246
257
|
@classmethod
|
|
247
|
-
def _wrap_error(cls, result, raise_e
|
|
258
|
+
def _wrap_error(cls, result, raise_e=False):
|
|
248
259
|
code = result["code"]
|
|
249
|
-
if code == 0:
|
|
260
|
+
if code == 0:
|
|
261
|
+
return False
|
|
250
262
|
if raise_e:
|
|
251
263
|
raise exceptions.OperationalError(
|
|
252
|
-
message
|
|
253
|
-
result.get("stdout", "")
|
|
264
|
+
message=result.get("stderr", "") or result.get("stdout", "")
|
|
254
265
|
)
|
|
255
266
|
return True
|
appier/graph.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -40,6 +31,7 @@ __license__ = "Apache License, Version 2.0"
|
|
|
40
31
|
from . import defines
|
|
41
32
|
from . import queuing
|
|
42
33
|
|
|
34
|
+
|
|
43
35
|
class Graph(object):
|
|
44
36
|
"""
|
|
45
37
|
Graph structure and associated algorithms. Made up by a dictionary of
|
|
@@ -63,7 +55,8 @@ class Graph(object):
|
|
|
63
55
|
cur, path = dst, []
|
|
64
56
|
while not cur == src:
|
|
65
57
|
path.append(cur)
|
|
66
|
-
if not cur in prev:
|
|
58
|
+
if not cur in prev:
|
|
59
|
+
return []
|
|
67
60
|
cur = prev[cur]
|
|
68
61
|
path.append(src)
|
|
69
62
|
path.reverse()
|
|
@@ -71,17 +64,22 @@ class Graph(object):
|
|
|
71
64
|
|
|
72
65
|
def add_edges(self, edges):
|
|
73
66
|
for edge in edges:
|
|
74
|
-
if len(edge) < 2:
|
|
67
|
+
if len(edge) < 2:
|
|
68
|
+
continue
|
|
75
69
|
src, dst = edge[0], edge[1]
|
|
76
70
|
cost = edge[2] if len(edge) > 2 and isinstance(edge[2], int) else 1
|
|
77
|
-
bidirectional =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
bidirectional = (
|
|
72
|
+
edge[3] if len(edge) > 3 and isinstance(edge[3], bool) else False
|
|
73
|
+
)
|
|
74
|
+
self.add_edge(src, dst, cost=cost, bidirectional=bidirectional)
|
|
75
|
+
|
|
76
|
+
def add_edge(self, src, dst, cost=1, bidirectional=False):
|
|
77
|
+
if not src in self.edges:
|
|
78
|
+
self.edges[src] = []
|
|
82
79
|
self.edges[src].append((dst, cost))
|
|
83
80
|
|
|
84
|
-
if bidirectional:
|
|
81
|
+
if bidirectional:
|
|
82
|
+
self.add_edge(dst, src, cost=cost, bidirectional=False)
|
|
85
83
|
|
|
86
84
|
def dijkstra(self, src, dst):
|
|
87
85
|
"""
|
|
@@ -96,28 +94,29 @@ class Graph(object):
|
|
|
96
94
|
:see: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
|
|
97
95
|
"""
|
|
98
96
|
|
|
99
|
-
if src == dst:
|
|
97
|
+
if src == dst:
|
|
98
|
+
return [src], 0
|
|
100
99
|
|
|
101
100
|
cls = self.__class__
|
|
102
101
|
dist, prev = dict(), dict()
|
|
103
102
|
dist[src] = 0
|
|
104
103
|
|
|
105
104
|
queue = queuing.MemoryQueue()
|
|
106
|
-
queue.push(src, priority
|
|
105
|
+
queue.push(src, priority=0)
|
|
107
106
|
|
|
108
107
|
while queue.length() > 0:
|
|
109
|
-
(_, _, top) = queue.pop(full
|
|
108
|
+
(_, _, top) = queue.pop(full=True)
|
|
110
109
|
dist[top] = dist[top] if top in dist else defines.INFINITY
|
|
111
110
|
|
|
112
111
|
edges = self.edges[top] if top in self.edges else []
|
|
113
|
-
for
|
|
112
|
+
for nxt, cost in edges:
|
|
114
113
|
dist[nxt] = dist[nxt] if nxt in dist else defines.INFINITY
|
|
115
114
|
|
|
116
115
|
alt = dist[top] + cost
|
|
117
116
|
if alt < dist[nxt]:
|
|
118
117
|
dist[nxt] = alt
|
|
119
118
|
prev[nxt] = top
|
|
120
|
-
queue.push(nxt, priority
|
|
119
|
+
queue.push(nxt, priority=dist[nxt])
|
|
121
120
|
|
|
122
121
|
path = cls._build_path(prev, src, dst)
|
|
123
122
|
cost = dist[dst] if dst in dist else defines.INFINITY
|