Skip to content

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Nov 8, 2019
1 parent 5ea62cb commit a5b6983
Show file tree
Hide file tree
Showing 18 changed files with 1,116 additions and 1,154 deletions.
353 changes: 172 additions & 181 deletions packages/snet_cli/snet/snet_cli/mpe_channel_command.py

Large diffs are not rendered by default.

57 changes: 29 additions & 28 deletions packages/snet_cli/snet/snet_cli/mpe_orgainzation_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ def default(self, o):


class PaymentStorageClient(object):
def __init__(self, connection_timeout=None, request_timeout="", endpoints=None):
def __init__(self,
connection_timeout=None,
request_timeout="",
endpoints=None):
self.connection_timeout = connection_timeout
self.request_timeout = request_timeout
self.endpoints = endpoints if endpoints else []

def add_payment_storage_client_details(
self, connection_time_out, request_timeout, endpoints
):
def add_payment_storage_client_details(self, connection_time_out,
request_timeout, endpoints):
self.connection_timeout = connection_time_out
self.request_timeout = request_timeout
self.endpoints = endpoints
Expand All @@ -27,16 +29,17 @@ def from_json(cls, json_data: dict):

def validate(self):
if len(self.endpoints) < 1:
raise Exception("At least one endpoint is required for payment channel ")
raise Exception(
"At least one endpoint is required for payment channel ")


class Payment(object):
def __init__(
self,
payment_address="",
payment_expiration_threshold="",
payment_channel_storage_type="",
payment_channel_storage_client=PaymentStorageClient(),
self,
payment_address="",
payment_expiration_threshold="",
payment_channel_storage_type="",
payment_channel_storage_client=PaymentStorageClient(),
):
self.payment_address = payment_address
self.payment_expiration_threshold = payment_expiration_threshold
Expand All @@ -46,8 +49,7 @@ def __init__(
@classmethod
def from_json(cls, json_data: dict):
payment_channel_storage_client = PaymentStorageClient.from_json(
json_data["payment_channel_storage_client"]
)
json_data["payment_channel_storage_client"])
return cls(
json_data["payment_address"],
json_data["payment_expiration_threshold"],
Expand Down Expand Up @@ -103,16 +105,17 @@ def validate(self):
raise Exception("group_id is cannot be null")

if self.payment is None:
raise Exception(
"payment details cannot be null for group_name %s", self.group_name
)
raise Exception("payment details cannot be null for group_name %s",
self.group_name)
else:
self.payment.validate()

def update_payment_expiration_threshold(self, payment_expiration_threshold):
def update_payment_expiration_threshold(self,
payment_expiration_threshold):
self.payment.payment_expiration_threshold = payment_expiration_threshold

def update_payment_channel_storage_type(self, payment_channel_storage_type):
def update_payment_channel_storage_type(self,
payment_channel_storage_type):
self.update_payment_channel_storage_type = payment_channel_storage_type

def update_payment_address(self, payment_address):
Expand Down Expand Up @@ -208,18 +211,16 @@ def from_file(cls, filepath):

@staticmethod
def is_removing_existing_group_from_org(
current_group_name, existing_registry_metadata_group_names
):
if len(existing_registry_metadata_group_names - current_group_name) == 0:
current_group_name, existing_registry_metadata_group_names):
if len(existing_registry_metadata_group_names -
current_group_name) == 0:
pass
else:
remvoved_groups = (
existing_registry_metadata_group_names - current_group_name
)
remvoved_groups = (existing_registry_metadata_group_names -
current_group_name)
raise Exception(
"Cannot remove existing group from organization as it might be attached to services, "
"groups you are removing are %s" % remvoved_groups
)
"groups you are removing are %s" % remvoved_groups)

def validate(self, existing_registry_metadata=None):

Expand All @@ -235,7 +236,8 @@ def validate(self, existing_registry_metadata=None):
if len(unique_group_names) < len(self.groups):
raise Exception("Cannot create group with duplicate names")
if len(self.groups) < 1:
raise Exception("At least One group is required to create an organization")
raise Exception(
"At least One group is required to create an organization")
else:
for group in self.groups:
group.validate()
Expand All @@ -246,8 +248,7 @@ def validate(self, existing_registry_metadata=None):
existing_registry_metadata_group_names.add(group.group_name)

self.is_removing_existing_group_from_org(
unique_group_names, existing_registry_metadata_group_names
)
unique_group_names, existing_registry_metadata_group_names)

def get_payment_address_for_group(self, group_name):
for group in self.groups:
Expand Down
101 changes: 48 additions & 53 deletions packages/snet_cli/snet/snet_cli/mpe_service_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class AssetType(Enum):
@staticmethod
def is_single_value(asset_type):
if asset_type in [
AssetType.HERO_IMAGE.value,
AssetType.DOCUMENTATION.value,
AssetType.TERMS_OF_USE.value,
AssetType.HERO_IMAGE.value,
AssetType.DOCUMENTATION.value,
AssetType.TERMS_OF_USE.value,
]:
return True

Expand All @@ -78,15 +78,10 @@ def __init__(self):
}

def set_simple_field(self, f, v):
if (
f != "display_name"
and f != "encoding"
and f != "model_ipfs_hash"
and f != "mpe_address"
and f != "service_type"
and f != "payment_expiration_threshold"
and f != "service_description"
):
if (f != "display_name" and f != "encoding" and f != "model_ipfs_hash"
and f != "mpe_address" and f != "service_type"
and f != "payment_expiration_threshold"
and f != "service_description"):
raise Exception("unknown field in MPEServiceMetadata")
self.m[f] = v

Expand All @@ -106,25 +101,20 @@ def set_fixed_price_in_cogs(self, group_name, price):
if pricing["price_model"] == "fixed_price":
is_fixed_price_enabled = True
if not is_fixed_price_enabled:
group["pricing"].append(
{
"price_model": "fixed_price",
"price_in_cogs": price,
"default": True,
}
)
else:
group["pricing"] = [
{
group["pricing"].append({
"price_model": "fixed_price",
"price_in_cogs": price,
"default": True,
}
]

def set_method_price_in_cogs(
self, group_name, package_name, service_name, method, price
):
})
else:
group["pricing"] = [{
"price_model": "fixed_price",
"price_in_cogs": price,
"default": True,
}]

def set_method_price_in_cogs(self, group_name, package_name, service_name,
method, price):
if type(price) != int:
raise Exception("Price should have int type")

Expand All @@ -137,7 +127,10 @@ def set_method_price_in_cogs(

service_name = service_name
package_name = package_name
method_pricing = {"method_name": method, "price_in_cogs": price}
method_pricing = {
"method_name": method,
"price_in_cogs": price
}
pricings = []

if "pricings" in group:
Expand All @@ -155,41 +148,41 @@ def set_method_price_in_cogs(
if detail["service_name"] == service_name:
# adding new method pricing for existing service
fixed_price_method_pricing_for_service_exist = True
detail["method_pricing"].append(method_pricing)
detail["method_pricing"].append(
method_pricing)

if not fixed_price_method_pricing_for_service_exist:
# pricing for new method for new service
pricing["details"].append(
{
"service_name": service_name,
"method_pricing": [method_pricing],
}
)
else:
pricing["details"] = [
{
"service_name": service_name,
pricing["details"].append({
"service_name":
service_name,
"method_pricing": [method_pricing],
}
]
})
else:
pricing["details"] = [{
"service_name":
service_name,
"method_pricing": [method_pricing],
}]

if not fixed_price_method_model_exist:
fixed_price_per_method = {
"package_name": package_name,
"price_model": "fixed_price_per_method",
"details": [
{
"service_name": service_name,
"method_pricing": [method_pricing],
}
],
"package_name":
package_name,
"price_model":
"fixed_price_per_method",
"details": [{
"service_name": service_name,
"method_pricing": [method_pricing],
}],
}
group["pricings"] = [fixed_price_per_method]

def add_group(self, group_name):
""" Return new group_id in base64 """
if self.is_group_name_exists(group_name):
raise Exception('the group "%s" is already present' % str(group_name))
raise Exception('the group "%s" is already present' %
str(group_name))

self.m["groups"] += [{"group_name": group_name}]

Expand Down Expand Up @@ -238,7 +231,8 @@ def add_endpoint_to_group(self, group_name, endpoint):
if not self.is_group_name_exists(group_name):
raise Exception("the group %s is not present" % str(group_name))
if endpoint in self.get_all_endpoints_for_group(group_name):
raise Exception("the endpoint %s is already present" % str(endpoint))
raise Exception("the endpoint %s is already present" %
str(endpoint))

groups = self.m["groups"]
for group in groups:
Expand Down Expand Up @@ -351,7 +345,8 @@ def get_all_endpoints_with_group_name(self):
def get_endpoints_for_group(self, group_name=None):
group_name = self.get_group_name_nonetrick(group_name)
return [
e["endpoint"] for e in self.m["endpoints"] if e["group_name"] == group_name
e["endpoint"] for e in self.m["endpoints"]
if e["group_name"] == group_name
]


Expand Down
Loading

0 comments on commit a5b6983

Please sign in to comment.