Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit b0a9d56

Browse files
author
totokaka
committed
Simplify methods conserning builds
1 parent 5f47f9c commit b0a9d56

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

mcman/logic/servers.py

+15-27
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,7 @@ def builds(server, channel, version, size):
103103
the error dictionary from SpaceGDN is returned.
104104
105105
"""
106-
server = spacegdn.get_id(jar=server)
107-
if server == -1:
108-
raise ValueError('Could not find server')
109-
if channel is not None:
110-
channel = spacegdn.get_id(jar=server, channel=channel)
111-
if channel == -1:
112-
raise ValueError('Could not find channel')
113-
if version is not None:
114-
version = spacegdn.get_id(jar=server, channel=channel, version=version)
115-
if version == -1:
116-
raise ValueError('Could not find version')
117-
result = spacegdn.builds(jar=server, channel=channel, version=version)
106+
result = get_builds(server, channel, version, None)
118107

119108
if type(result) is not list:
120109
return result
@@ -130,6 +119,15 @@ def builds(server, channel, version, size):
130119
return result
131120

132121

122+
def get_id_raise_valueerror(name, jar=None, channel=None, version=None,
123+
build=None):
124+
result = spacegdn.get_id(jar=jar, channel=channel, version=version,
125+
build=build)
126+
if result == -1:
127+
raise ValueError('Could not find {}'.format(name))
128+
return result
129+
130+
133131
def get_builds(server, channel, version, build):
134132
""" Get the build.
135133
@@ -139,24 +137,14 @@ def get_builds(server, channel, version, build):
139137
as returned by SpaceGDN.
140138
141139
"""
142-
server = spacegdn.get_id(jar=server)
143-
if server == -1:
144-
raise ValueError('Could not find server')
140+
server = get_id_raise_valueerror('server', server)
145141
if channel is not None:
146-
channel = spacegdn.get_id(jar=server, channel=channel)
147-
if channel == -1:
148-
raise ValueError('Could not find channel')
142+
channel = get_id_raise_valueerror('channel', server, channel)
149143
if version is not None:
150-
version = spacegdn.get_id(jar=server, channel=channel,
151-
version=version)
152-
if version == -1:
153-
raise ValueError('Could not find version')
144+
version = get_id_raise_valueerror('version', server, channel, version)
154145
if build is not None:
155-
build = spacegdn.get_id(jar=server, channel=channel,
156-
version=version,
157-
build=build)
158-
if build == -1:
159-
raise ValueError('Could not find build')
146+
build = get_id_raise_valueerror('build', server, channel, version,
147+
build)
160148

161149
return spacegdn.builds(jar=server, channel=channel,
162150
version=version, build=build)

0 commit comments

Comments
 (0)