-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode.py
75 lines (67 loc) · 2.4 KB
/
node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright (c) 2018-2021 FASTEN.
#
# This file is part of FASTEN
# (see https://www.fasten-project.eu/).
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
class Node:
def __init__(self, uri_str, metadata, product="", version=""):
self.uri_str = uri_str
self.product = product
self.version = version
self.metadata = metadata
self.internal = False
self.external = False
self.undefined = False
self.static = False
self.entity = ""
if uri_str.startswith("///"):
self.undefined = True
self.external = True
self.entity = uri_str[3:]
elif uri_str.startswith("//"):
self.external = True
self.entity = uri_str[uri_str[2:].find('/')+3:]
self.product = uri_str[2:uri_str.find('/', 2)]
else:
self.entity = uri_str[1:]
self.internal = True
if ';' in self.entity.split('/')[-1]:
self.static = True
def get_product(self):
return self.product
def get_version(self):
return self.version
def get_entity(self):
return self.entity
def to_string(self):
forge_product_version = self.product # For now we skip forge
if self.version:
forge_product_version += "$" + self.version
return "fasten://{}/{}".format(forge_product_version, self.entity)
def __str__(self):
return "{} ({}, {}, {}, {})".format(
repr(self.uri_str),
repr(self.product),
repr(self.version),
repr(self.metadata),
repr(self.entity)
)
def __repr__(self):
return self.__str__()