1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional pkg_information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import requests |
17
|
|
|
import six.moves.http_client as http_client |
18
|
|
|
|
19
|
|
|
from st2actions.runners import pythonrunner |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class ListPackagesAction(pythonrunner.Action): |
23
|
|
|
|
24
|
|
|
def run(self, repo, package, distro_version, version, release, api_token, url): |
25
|
|
|
page = 1 |
26
|
|
|
packages = [] |
27
|
|
|
|
28
|
|
|
while page < 100: |
29
|
|
|
page_url = url + '?page=' + str(page) |
30
|
|
|
response = requests.get(page_url) |
31
|
|
|
|
32
|
|
|
if response.status_code != http_client.OK: |
33
|
|
|
raise Exception(response.text) |
34
|
|
|
|
35
|
|
|
packages += response.json() |
36
|
|
|
|
37
|
|
|
if len(packages) >= int(response.headers.get('Total', 0)): |
38
|
|
|
break |
39
|
|
|
|
40
|
|
|
page += 1 |
41
|
|
|
|
42
|
|
|
if package: |
43
|
|
|
packages = [pkg_info for pkg_info in packages if pkg_info['name'] == package] |
44
|
|
|
|
45
|
|
|
if distro_version: |
46
|
|
|
packages = [pkg_info for pkg_info in packages if pkg_info['distro_version'] == distro_version] |
47
|
|
|
|
48
|
|
|
if version: |
49
|
|
|
packages = [pkg_info for pkg_info in packages if pkg_info['version'] == version] |
50
|
|
|
|
51
|
|
|
if release: |
52
|
|
|
packages = [pkg_info for pkg_info in packages if pkg_info['release'] ==release] |
53
|
|
|
|
54
|
|
|
return sorted(packages, key=lambda x: (x['version'], x['release']), reverse=True) |
55
|
|
|
|