rhdl 0.1.0.post1769067367__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.
- rhdl-0.1.0.post1769067367.dist-info/METADATA +22 -0
- rhdl-0.1.0.post1769067367.dist-info/RECORD +18 -0
- rhdl-0.1.0.post1769067367.dist-info/WHEEL +5 -0
- rhdl-0.1.0.post1769067367.dist-info/entry_points.txt +2 -0
- rhdl-0.1.0.post1769067367.dist-info/licenses/LICENSE +201 -0
- rhdl-0.1.0.post1769067367.dist-info/top_level.txt +1 -0
- rhdlcli/__init__.py +0 -0
- rhdlcli/api.py +144 -0
- rhdlcli/cli.py +218 -0
- rhdlcli/downloader.py +45 -0
- rhdlcli/files.py +52 -0
- rhdlcli/fs.py +23 -0
- rhdlcli/main.py +50 -0
- rhdlcli/options.py +57 -0
- rhdlcli/pull_secret.py +38 -0
- rhdlcli/stats.py +26 -0
- rhdlcli/validator.py +32 -0
- rhdlcli/version.py +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rhdl
|
|
3
|
+
Version: 0.1.0.post1769067367
|
|
4
|
+
Summary: RHDL CLI module
|
|
5
|
+
Home-page: https://doc.rhdl.distributed-ci.io/
|
|
6
|
+
Author: Distributed CI team
|
|
7
|
+
Author-email: distributed-ci@redhat.com
|
|
8
|
+
License: Apache v2.0
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: rhdllib
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: summary
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
rhdl-0.1.0.post1769067367.dist-info/licenses/LICENSE,sha256=RVVnHNsitM_UrrOOZTEpvbjNHs-IZ4wgkeaWaYeNXRE,11337
|
|
2
|
+
rhdlcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
rhdlcli/api.py,sha256=5CnTrM7LdwP6F9QCw7Bex66hP8mY3GR68nR4M5-F768,4608
|
|
4
|
+
rhdlcli/cli.py,sha256=1JKBx89tNO5f44chYJBzZ8P1yF0yTyrdqerXLuD-Vsg,7195
|
|
5
|
+
rhdlcli/downloader.py,sha256=cJ1UaWn6tUAiGTlaPu9xxhirWve_tggCu5tElNwaQjY,1435
|
|
6
|
+
rhdlcli/files.py,sha256=SMYUn0aI4V9yueV6S-ymmbIrFf_gVQa0VSWVC_vqxBg,1560
|
|
7
|
+
rhdlcli/fs.py,sha256=tEO-5EujnTLmKN-IsH6Vj6ePISGOgHvgyUTQG0wYR7M,544
|
|
8
|
+
rhdlcli/main.py,sha256=6-_sMeh4RYBA5Y8hFX_hUSC3qOgHRh9ZjYaBjnMNbik,1270
|
|
9
|
+
rhdlcli/options.py,sha256=RUj3xXgzIyrHJ-R2sFGBDUc-5SwcYKtBs_dJIWUn19Y,1746
|
|
10
|
+
rhdlcli/pull_secret.py,sha256=iccyZRzlu4YAvyjroqRquWwFnI0rIytjpstAY0n5Ye0,1207
|
|
11
|
+
rhdlcli/stats.py,sha256=MvwxMr4LAm3PM5qiEnuB8thUgzBolWPLKg6ql53QU_Y,786
|
|
12
|
+
rhdlcli/validator.py,sha256=zpX_f1g2UeDUjFk0a7HzR3YydryC3k9QgaUc2C1Lp4g,950
|
|
13
|
+
rhdlcli/version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
14
|
+
rhdl-0.1.0.post1769067367.dist-info/METADATA,sha256=c2fAXlFWR8_FqhzmJnbZMWBEWkP6iZmxdMND_KifH4A,607
|
|
15
|
+
rhdl-0.1.0.post1769067367.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
16
|
+
rhdl-0.1.0.post1769067367.dist-info/entry_points.txt,sha256=JWiBdHm5nD1m3_XZR0QtIuPmuvsJKE-43YhQxCINb8w,43
|
|
17
|
+
rhdl-0.1.0.post1769067367.dist-info/top_level.txt,sha256=1kLkHuRFxHGxPUkrCL28sF6wqXmu3IGhJT858T4XRaI,8
|
|
18
|
+
rhdl-0.1.0.post1769067367.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019 Red Hat
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rhdlcli
|
rhdlcli/__init__.py
ADDED
|
File without changes
|
rhdlcli/api.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
9
|
+
from functools import wraps
|
|
10
|
+
from urllib.parse import urljoin
|
|
11
|
+
from rhdlcli.fs import create_parent_dir
|
|
12
|
+
from rhdllib.auth import HmacAuthBase
|
|
13
|
+
|
|
14
|
+
FIVE_SECONDS = 5
|
|
15
|
+
TEN_SECONDS = 10
|
|
16
|
+
# We'll allow 5 seconds to connect & 10 seconds to get an answer
|
|
17
|
+
REQUESTS_TIMEOUT = (FIVE_SECONDS, TEN_SECONDS)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HmacSession(requests.Session):
|
|
21
|
+
def __init__(self, base_url, access_key, secret_key):
|
|
22
|
+
self.base_url = base_url
|
|
23
|
+
self.access_key = access_key
|
|
24
|
+
self.secret_key = secret_key
|
|
25
|
+
super(HmacSession, self).__init__()
|
|
26
|
+
|
|
27
|
+
def request(self, method, url, *args, allow_redirects=True, **kwargs):
|
|
28
|
+
url = urljoin(self.base_url, url)
|
|
29
|
+
auth = HmacAuthBase(
|
|
30
|
+
self.access_key, self.secret_key, service="api", region="us-east-1"
|
|
31
|
+
)
|
|
32
|
+
response = super(HmacSession, self).request(
|
|
33
|
+
method, url, auth=auth, allow_redirects=False, *args, **kwargs
|
|
34
|
+
)
|
|
35
|
+
if response.status_code == 302 and allow_redirects:
|
|
36
|
+
redirect_url = response.headers.get("Location")
|
|
37
|
+
return super(HmacSession, self).request(
|
|
38
|
+
method, redirect_url, *args, **kwargs
|
|
39
|
+
)
|
|
40
|
+
return response
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def retry(tries=3, delay=2, multiplier=2):
|
|
44
|
+
def decorated_retry(f):
|
|
45
|
+
@wraps(f)
|
|
46
|
+
def f_retry(*args, **kwargs):
|
|
47
|
+
_tries = tries
|
|
48
|
+
_delay = delay
|
|
49
|
+
while _tries:
|
|
50
|
+
try:
|
|
51
|
+
return f(*args, **kwargs)
|
|
52
|
+
except KeyboardInterrupt:
|
|
53
|
+
raise
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print("%s, retrying in %d seconds..." % (str(e), _delay))
|
|
56
|
+
time.sleep(_delay)
|
|
57
|
+
_tries -= 1
|
|
58
|
+
if not _tries:
|
|
59
|
+
raise
|
|
60
|
+
_delay *= multiplier
|
|
61
|
+
return f(*args, **kwargs)
|
|
62
|
+
|
|
63
|
+
return f_retry
|
|
64
|
+
|
|
65
|
+
return decorated_retry
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_component(options):
|
|
69
|
+
session = HmacSession(
|
|
70
|
+
base_url=options["base_url"],
|
|
71
|
+
access_key=options["access_key"],
|
|
72
|
+
secret_key=options["secret_key"],
|
|
73
|
+
)
|
|
74
|
+
compose = options["compose"]
|
|
75
|
+
r = session.get(
|
|
76
|
+
f"/api/v1/components?compose_id_startswith={compose}&state=active&sort=-released_at"
|
|
77
|
+
)
|
|
78
|
+
r.raise_for_status()
|
|
79
|
+
components = r.json()["components"]
|
|
80
|
+
if len(components) <= 0:
|
|
81
|
+
print(f"No component found with compose id starting with {compose}")
|
|
82
|
+
sys.exit(1)
|
|
83
|
+
return components[0]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@retry()
|
|
87
|
+
def get_files_list(session):
|
|
88
|
+
print("Download file list, it may take a few seconds")
|
|
89
|
+
r = session.get("rhdl_files_list.json")
|
|
90
|
+
r.raise_for_status()
|
|
91
|
+
return r.json()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@retry()
|
|
95
|
+
def download_file(session, download_folder, file, i, nb_files):
|
|
96
|
+
start_time = time.monotonic()
|
|
97
|
+
relative_file_path = os.path.join(file["path"], file["name"])
|
|
98
|
+
destination = os.path.join(download_folder, relative_file_path)
|
|
99
|
+
if os.path.exists(destination):
|
|
100
|
+
print(f"({i + 1}/{nb_files}): < Skipping {destination} file already exists")
|
|
101
|
+
return
|
|
102
|
+
print(f"({i + 1}/{nb_files}): < Getting {destination}")
|
|
103
|
+
create_parent_dir(destination)
|
|
104
|
+
r = session.get(relative_file_path)
|
|
105
|
+
r.raise_for_status()
|
|
106
|
+
with open(destination, "wb") as f:
|
|
107
|
+
for chunk in r.iter_content(chunk_size=1024 * 1024):
|
|
108
|
+
f.write(chunk)
|
|
109
|
+
download_speed = round(file["size"] / (time.monotonic() - start_time) / 1024, 2)
|
|
110
|
+
print(f"({i + 1}/{nb_files}): > Done {destination} - {download_speed} KB/s")
|
|
111
|
+
return file
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def download_files(session, download_folder, files):
|
|
115
|
+
nb_files = len(files)
|
|
116
|
+
with ThreadPoolExecutor(max_workers=10) as executor:
|
|
117
|
+
for file in executor.map(
|
|
118
|
+
download_file,
|
|
119
|
+
*zip(
|
|
120
|
+
*[
|
|
121
|
+
(session, download_folder, file, i, nb_files)
|
|
122
|
+
for i, file in enumerate(files)
|
|
123
|
+
]
|
|
124
|
+
),
|
|
125
|
+
):
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_pull_secret(options):
|
|
130
|
+
session = HmacSession(
|
|
131
|
+
base_url=options["base_url"],
|
|
132
|
+
access_key=options["access_key"],
|
|
133
|
+
secret_key=options["secret_key"],
|
|
134
|
+
)
|
|
135
|
+
r = session.get("/api/v1/teams/me/pull_secret")
|
|
136
|
+
r.raise_for_status()
|
|
137
|
+
pull_secret = r.json()["pull_secret"]
|
|
138
|
+
if pull_secret is None:
|
|
139
|
+
print(
|
|
140
|
+
"Your team currently does not have access to the Red Hat registry."
|
|
141
|
+
"Please reach out to an RHDL administrator for assistance."
|
|
142
|
+
)
|
|
143
|
+
sys.exit(1)
|
|
144
|
+
return pull_secret
|
rhdlcli/cli.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import pathlib
|
|
6
|
+
|
|
7
|
+
from rhdlcli.version import __version__
|
|
8
|
+
|
|
9
|
+
DESCRIPTION = "RHDL CLI - Download the latest RHEL compose easily."
|
|
10
|
+
|
|
11
|
+
COPYRIGHT = """
|
|
12
|
+
Copyright © 2026 Red Hat.
|
|
13
|
+
Licensed under the Apache License, Version 2.0
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def clean_with_default_values(parsed_arguments, cwd):
|
|
18
|
+
args_dict = vars(parsed_arguments)
|
|
19
|
+
|
|
20
|
+
if args_dict.get("command") == "download":
|
|
21
|
+
DEFAULT_INCLUDE_EXCLUDE_LIST = [
|
|
22
|
+
{"pattern": ".composeinfo", "type": "include"},
|
|
23
|
+
{"pattern": "metadata/*", "type": "include"},
|
|
24
|
+
{"pattern": "AppStream/x86_64/os/*", "type": "include"},
|
|
25
|
+
{"pattern": "BaseOS/x86_64/os/*", "type": "include"},
|
|
26
|
+
{"pattern": "*", "type": "exclude"},
|
|
27
|
+
]
|
|
28
|
+
if "include_and_exclude" not in args_dict:
|
|
29
|
+
args_dict["include_and_exclude"] = DEFAULT_INCLUDE_EXCLUDE_LIST
|
|
30
|
+
|
|
31
|
+
if "include" in args_dict:
|
|
32
|
+
del args_dict["include"]
|
|
33
|
+
if "exclude" in args_dict:
|
|
34
|
+
del args_dict["exclude"]
|
|
35
|
+
|
|
36
|
+
if args_dict.get("destination") is None:
|
|
37
|
+
base_path = pathlib.Path(cwd)
|
|
38
|
+
else:
|
|
39
|
+
base_path = pathlib.Path(cwd, args_dict["destination"]).resolve()
|
|
40
|
+
|
|
41
|
+
if not args_dict["flat"]:
|
|
42
|
+
base_path = base_path / args_dict["compose"]
|
|
43
|
+
|
|
44
|
+
args_dict["destination"] = os.fspath(base_path)
|
|
45
|
+
|
|
46
|
+
return args_dict
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class IncludeExcludeAction(argparse.Action):
|
|
50
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
51
|
+
if "include_and_exclude" not in namespace:
|
|
52
|
+
setattr(namespace, "include_and_exclude", [])
|
|
53
|
+
previous = namespace.include_and_exclude
|
|
54
|
+
previous.append({"pattern": values, "type": self.dest})
|
|
55
|
+
setattr(namespace, "include_and_exclude", previous)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def add_login_command(subparsers):
|
|
59
|
+
"""Add the login subcommand"""
|
|
60
|
+
login_parser = subparsers.add_parser(
|
|
61
|
+
"login",
|
|
62
|
+
help="Login to RHDL",
|
|
63
|
+
description="Authenticate with RHDL to access compose downloads.",
|
|
64
|
+
epilog=COPYRIGHT,
|
|
65
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
66
|
+
)
|
|
67
|
+
login_parser.set_defaults(command="login")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def add_download_command(subparsers):
|
|
71
|
+
"""Add the download subcommand"""
|
|
72
|
+
download_examples = """
|
|
73
|
+
examples:
|
|
74
|
+
# Download latest RHEL-10 compose in <cwd>/RHEL-10 folder
|
|
75
|
+
rhdl download RHEL-10
|
|
76
|
+
|
|
77
|
+
# Download latest RHEL-10 in /tmp/repo/RHEL-10 folder
|
|
78
|
+
rhdl download RHEL-10 --destination /tmp/repo
|
|
79
|
+
|
|
80
|
+
# Download directly in /tmp/repo/RHEL-10 without creating RHEL-10 subdirectory
|
|
81
|
+
rhdl download RHEL-10 --destination /tmp/repo/RHEL-10 --flat
|
|
82
|
+
|
|
83
|
+
# Download with custom include/exclude patterns
|
|
84
|
+
rhdl download RHEL-10 --include "*/x86_64/*" --exclude "*/debug/*"
|
|
85
|
+
|
|
86
|
+
# Download specific tag (nightly, candidate, ga)
|
|
87
|
+
rhdl download RHEL-10 --tag nightly
|
|
88
|
+
"""
|
|
89
|
+
download_parser = subparsers.add_parser(
|
|
90
|
+
"download",
|
|
91
|
+
help="Download a RHEL compose",
|
|
92
|
+
description="Download a specific RHEL compose with filtering options.",
|
|
93
|
+
epilog=download_examples + COPYRIGHT,
|
|
94
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
95
|
+
)
|
|
96
|
+
download_parser.add_argument(
|
|
97
|
+
"compose", metavar="COMPOSE", help="Compose ID or NAME (e.g., RHEL-10)"
|
|
98
|
+
)
|
|
99
|
+
download_parser.add_argument(
|
|
100
|
+
"-d",
|
|
101
|
+
"--destination",
|
|
102
|
+
metavar="DESTINATION",
|
|
103
|
+
help="Destination folder where a <COMPOSE> subdirectory will be created (default: current directory)",
|
|
104
|
+
)
|
|
105
|
+
download_parser.add_argument(
|
|
106
|
+
"--flat",
|
|
107
|
+
action="store_true",
|
|
108
|
+
default=False,
|
|
109
|
+
help="Download directly into destination folder without creating a subdirectory with the Compose ID",
|
|
110
|
+
)
|
|
111
|
+
download_parser.add_argument(
|
|
112
|
+
"-f",
|
|
113
|
+
"--force",
|
|
114
|
+
action="store_true",
|
|
115
|
+
default=False,
|
|
116
|
+
help="Force download even if destination folder already exists",
|
|
117
|
+
)
|
|
118
|
+
download_parser.add_argument(
|
|
119
|
+
"-i",
|
|
120
|
+
"--include",
|
|
121
|
+
action=IncludeExcludeAction,
|
|
122
|
+
metavar="PATTERN",
|
|
123
|
+
dest="include",
|
|
124
|
+
help="File paths pattern to download. Wildcard '*' authorized. Can be used multiple times.",
|
|
125
|
+
)
|
|
126
|
+
download_parser.add_argument(
|
|
127
|
+
"-e",
|
|
128
|
+
"--exclude",
|
|
129
|
+
action=IncludeExcludeAction,
|
|
130
|
+
metavar="PATTERN",
|
|
131
|
+
dest="exclude",
|
|
132
|
+
help="File paths pattern to exclude. Wildcard '*' authorized. Can be used multiple times.",
|
|
133
|
+
)
|
|
134
|
+
download_parser.add_argument(
|
|
135
|
+
"-t",
|
|
136
|
+
"--tag",
|
|
137
|
+
metavar="TAG",
|
|
138
|
+
default="milestone",
|
|
139
|
+
help="Filter RHEL compose with a tag (choices: milestone, nightly, candidate, ga) (default: milestone)",
|
|
140
|
+
)
|
|
141
|
+
download_parser.set_defaults(command="download")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def add_download_pull_secret_command(subparsers):
|
|
145
|
+
"""Add the download-pull-secret subcommand"""
|
|
146
|
+
pull_secret_examples = """
|
|
147
|
+
examples:
|
|
148
|
+
# Download pull-secret to default location (~/.docker/config.json)
|
|
149
|
+
rhdl download-pull-secret
|
|
150
|
+
|
|
151
|
+
# Download pull-secret to custom location
|
|
152
|
+
rhdl download-pull-secret --destination ./my-pull-secret.json
|
|
153
|
+
|
|
154
|
+
# Force overwrite existing file
|
|
155
|
+
rhdl download-pull-secret --force
|
|
156
|
+
|
|
157
|
+
# Merge with existing pull-secret
|
|
158
|
+
rhdl download-pull-secret --merge
|
|
159
|
+
"""
|
|
160
|
+
pull_secret_parser = subparsers.add_parser(
|
|
161
|
+
"download-pull-secret",
|
|
162
|
+
help="Download your team's pull-secret",
|
|
163
|
+
description="Download the pull-secret associated with your team for authenticating to container registries.",
|
|
164
|
+
epilog=pull_secret_examples + COPYRIGHT,
|
|
165
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
166
|
+
)
|
|
167
|
+
pull_secret_parser.add_argument(
|
|
168
|
+
"-d",
|
|
169
|
+
"--destination",
|
|
170
|
+
metavar="PATH",
|
|
171
|
+
default=os.path.expanduser("~/.docker/config.json"),
|
|
172
|
+
help="Destination file path for the pull-secret (default: ~/.docker/config.json)",
|
|
173
|
+
)
|
|
174
|
+
pull_secret_parser.add_argument(
|
|
175
|
+
"-f",
|
|
176
|
+
"--force",
|
|
177
|
+
action="store_true",
|
|
178
|
+
default=False,
|
|
179
|
+
help="Force overwrite if destination file already exists",
|
|
180
|
+
)
|
|
181
|
+
pull_secret_parser.add_argument(
|
|
182
|
+
"-m",
|
|
183
|
+
"--merge",
|
|
184
|
+
action="store_true",
|
|
185
|
+
default=False,
|
|
186
|
+
help="Merge with existing pull-secret instead of replacing it",
|
|
187
|
+
)
|
|
188
|
+
pull_secret_parser.set_defaults(command="download-pull-secret")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def parse_arguments(arguments, cwd=None):
|
|
192
|
+
cwd = cwd or os.getcwd()
|
|
193
|
+
parser = argparse.ArgumentParser(
|
|
194
|
+
prog="rhdl",
|
|
195
|
+
description=DESCRIPTION,
|
|
196
|
+
epilog=COPYRIGHT,
|
|
197
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
198
|
+
)
|
|
199
|
+
parser.add_argument("--version", action="version", version=__version__)
|
|
200
|
+
|
|
201
|
+
subparsers = parser.add_subparsers(
|
|
202
|
+
title="commands",
|
|
203
|
+
description="Available commands",
|
|
204
|
+
dest="command",
|
|
205
|
+
help="Use 'rhdl COMMAND --help' for more information on a command",
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
add_login_command(subparsers)
|
|
209
|
+
add_download_command(subparsers)
|
|
210
|
+
add_download_pull_secret_command(subparsers)
|
|
211
|
+
|
|
212
|
+
parsed_arguments = parser.parse_args(arguments)
|
|
213
|
+
|
|
214
|
+
if parsed_arguments.command is None:
|
|
215
|
+
parser.print_help()
|
|
216
|
+
raise SystemExit(1)
|
|
217
|
+
|
|
218
|
+
return clean_with_default_values(parsed_arguments, cwd)
|
rhdlcli/downloader.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
from rhdlcli.api import (
|
|
6
|
+
get_component,
|
|
7
|
+
get_files_list,
|
|
8
|
+
download_files,
|
|
9
|
+
HmacSession,
|
|
10
|
+
)
|
|
11
|
+
from rhdlcli.stats import check_download_folder_has_enough_space
|
|
12
|
+
from rhdlcli.files import get_files_to_remove, filter_files
|
|
13
|
+
from rhdlcli.fs import mkdir_p
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def clean_download_folder(download_folder, files):
|
|
17
|
+
print("Verifying local mirror, this may take some time")
|
|
18
|
+
|
|
19
|
+
if not os.path.isdir(download_folder):
|
|
20
|
+
mkdir_p(download_folder)
|
|
21
|
+
|
|
22
|
+
for file in get_files_to_remove(download_folder, files):
|
|
23
|
+
print(f"Remove file {file}")
|
|
24
|
+
os.remove(file)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def download_component(options):
|
|
28
|
+
component = get_component(options)
|
|
29
|
+
print(
|
|
30
|
+
f"Downloading component: {component['compose_id']} in {options['destination']}"
|
|
31
|
+
)
|
|
32
|
+
session = HmacSession(
|
|
33
|
+
base_url=urljoin(
|
|
34
|
+
options["base_url"], f"/api/v1/components/{component['compose_id']}/files/"
|
|
35
|
+
),
|
|
36
|
+
access_key=options["access_key"],
|
|
37
|
+
secret_key=options["secret_key"],
|
|
38
|
+
)
|
|
39
|
+
files_list = get_files_list(session)
|
|
40
|
+
files = files_list["files"]
|
|
41
|
+
files = filter_files(files, options["include_and_exclude"])
|
|
42
|
+
download_folder = options["destination"]
|
|
43
|
+
clean_download_folder(download_folder, files)
|
|
44
|
+
check_download_folder_has_enough_space(download_folder, files)
|
|
45
|
+
download_files(session, download_folder, files)
|
rhdlcli/files.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import fnmatch
|
|
4
|
+
import hashlib
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _sha256_hexdigest_file(filepath):
|
|
9
|
+
m = hashlib.sha256()
|
|
10
|
+
with open(filepath, mode="rb") as fd:
|
|
11
|
+
for data in fd:
|
|
12
|
+
m.update(data)
|
|
13
|
+
return m.hexdigest()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _file_clean(file_path, sha256):
|
|
17
|
+
return _sha256_hexdigest_file(file_path) == sha256
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_files_to_remove(download_folder, files):
|
|
21
|
+
files_list_paths = {}
|
|
22
|
+
for file in files:
|
|
23
|
+
file_path = os.path.join(download_folder, file["path"], file["name"])
|
|
24
|
+
files_list_paths[file_path] = file
|
|
25
|
+
files_to_remove = []
|
|
26
|
+
for root, dirs, files in os.walk(download_folder):
|
|
27
|
+
for file in files:
|
|
28
|
+
file_path = os.path.join(root, file)
|
|
29
|
+
if os.path.islink(file_path):
|
|
30
|
+
continue
|
|
31
|
+
if file_path not in files_list_paths or not _file_clean(
|
|
32
|
+
file_path, files_list_paths[file_path]["sha256"]
|
|
33
|
+
):
|
|
34
|
+
files_to_remove.append(file_path)
|
|
35
|
+
return files_to_remove
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def filter_files(files, include_and_exclude):
|
|
39
|
+
new_files = []
|
|
40
|
+
for file in files:
|
|
41
|
+
relative_path = os.path.join(file["path"], file["name"])
|
|
42
|
+
matching_pattern = False
|
|
43
|
+
for ie in include_and_exclude:
|
|
44
|
+
if fnmatch.fnmatch(relative_path, ie["pattern"]):
|
|
45
|
+
matching_pattern = True
|
|
46
|
+
if ie["type"] == "include":
|
|
47
|
+
new_files.append(file)
|
|
48
|
+
break
|
|
49
|
+
if not matching_pattern:
|
|
50
|
+
new_files.append(file)
|
|
51
|
+
|
|
52
|
+
return new_files
|
rhdlcli/fs.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import errno
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def mkdir_p(path):
|
|
6
|
+
try:
|
|
7
|
+
os.makedirs(path)
|
|
8
|
+
except OSError as exc:
|
|
9
|
+
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
|
10
|
+
pass
|
|
11
|
+
elif exc.errno in [errno.EPERM, errno.EACCES]:
|
|
12
|
+
print(f"Permission error on {path}")
|
|
13
|
+
else:
|
|
14
|
+
raise
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def create_parent_dir(path):
|
|
18
|
+
mkdir_p(os.path.dirname(path))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_config_path(env_variables):
|
|
22
|
+
path = env_variables.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
|
|
23
|
+
return os.path.join(path, "rhdl")
|
rhdlcli/main.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import functools
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from rhdlcli.cli import parse_arguments
|
|
8
|
+
from rhdlcli.downloader import download_component
|
|
9
|
+
from rhdlcli.pull_secret import download_pull_secret
|
|
10
|
+
from rhdlcli.options import build_options, login
|
|
11
|
+
from rhdlcli.validator import (
|
|
12
|
+
exit_if_credentials_invalid,
|
|
13
|
+
exit_if_destination_exists,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def catch_all_and_print(f):
|
|
18
|
+
@functools.wraps(f)
|
|
19
|
+
def inner(*args, **kwargs):
|
|
20
|
+
try:
|
|
21
|
+
return f(*args, **kwargs)
|
|
22
|
+
except KeyboardInterrupt:
|
|
23
|
+
print("Keyboard interrupt exiting...")
|
|
24
|
+
sys.exit(130)
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(e)
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
|
|
29
|
+
return inner
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@catch_all_and_print
|
|
33
|
+
def main():
|
|
34
|
+
cwd = os.path.realpath(os.getcwd())
|
|
35
|
+
arguments = parse_arguments(sys.argv[1:], cwd)
|
|
36
|
+
env_variables = dict(os.environ)
|
|
37
|
+
options = build_options(arguments, env_variables)
|
|
38
|
+
if options["command"] == "login":
|
|
39
|
+
login(options)
|
|
40
|
+
return
|
|
41
|
+
exit_if_credentials_invalid(options)
|
|
42
|
+
if options["command"] == "download-pull-secret":
|
|
43
|
+
download_pull_secret(options)
|
|
44
|
+
return
|
|
45
|
+
exit_if_destination_exists(options)
|
|
46
|
+
download_component(options)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
main()
|
rhdlcli/options.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import getpass
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from rhdlcli.fs import get_config_path
|
|
6
|
+
|
|
7
|
+
CREDENTIAL_FILE_NAME = "credentials.json"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def read_credentials_file(app_config_path):
|
|
11
|
+
credential_file_path = os.path.join(app_config_path, CREDENTIAL_FILE_NAME)
|
|
12
|
+
if not os.path.isfile(credential_file_path):
|
|
13
|
+
|
|
14
|
+
return {}
|
|
15
|
+
with open(credential_file_path) as f:
|
|
16
|
+
return json.load(f)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def build_options(arguments, env_variables):
|
|
20
|
+
options = {}
|
|
21
|
+
options.update(arguments)
|
|
22
|
+
app_config_path = get_config_path(env_variables)
|
|
23
|
+
credentials = read_credentials_file(app_config_path)
|
|
24
|
+
options.update(
|
|
25
|
+
{
|
|
26
|
+
"app_config_path": app_config_path,
|
|
27
|
+
"base_url": env_variables.get("RHDL_API_URL", credentials.get("base_url")),
|
|
28
|
+
"access_key": env_variables.get(
|
|
29
|
+
"RHDL_ACCESS_KEY", credentials.get("access_key")
|
|
30
|
+
),
|
|
31
|
+
"secret_key": env_variables.get(
|
|
32
|
+
"RHDL_SECRET_KEY", credentials.get("secret_key")
|
|
33
|
+
),
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
return options
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def login(options):
|
|
40
|
+
app_config_path = options["app_config_path"]
|
|
41
|
+
if not os.path.exists(app_config_path):
|
|
42
|
+
os.makedirs(app_config_path)
|
|
43
|
+
|
|
44
|
+
access_key = input("RHDL Access Key: ")
|
|
45
|
+
secret_key = getpass.getpass("RHDL Secret Key: ")
|
|
46
|
+
default_base_url = "https://api.rhdl.distributed-ci.io"
|
|
47
|
+
base_url = input(f"RHDL server host ({default_base_url}):") or default_base_url
|
|
48
|
+
credentials = {
|
|
49
|
+
"base_url": base_url,
|
|
50
|
+
"access_key": access_key,
|
|
51
|
+
"secret_key": secret_key,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
file_path = os.path.join(app_config_path, CREDENTIAL_FILE_NAME)
|
|
55
|
+
with open(file_path, "w") as f:
|
|
56
|
+
json.dump(credentials, f)
|
|
57
|
+
print(f"Credential saved in {file_path}")
|
rhdlcli/pull_secret.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from rhdlcli.api import get_pull_secret
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def download_pull_secret(options):
|
|
7
|
+
destination = options["destination"]
|
|
8
|
+
force = options["force"]
|
|
9
|
+
merge = options["merge"]
|
|
10
|
+
|
|
11
|
+
if os.path.exists(destination) and not force and not merge:
|
|
12
|
+
raise FileExistsError(
|
|
13
|
+
f"File {destination} already exists. Use --force or --merge to overwrite."
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
pull_secret = get_pull_secret(options)
|
|
17
|
+
|
|
18
|
+
if merge and os.path.exists(destination):
|
|
19
|
+
with open(destination, "r") as f:
|
|
20
|
+
existing_data = json.load(f)
|
|
21
|
+
new_data = json.loads(pull_secret)
|
|
22
|
+
|
|
23
|
+
existing_keys = set(existing_data["auths"].keys())
|
|
24
|
+
new_keys = set(new_data["auths"].keys())
|
|
25
|
+
conflicting_keys = existing_keys & new_keys
|
|
26
|
+
|
|
27
|
+
if conflicting_keys and not force:
|
|
28
|
+
raise FileExistsError(
|
|
29
|
+
f"Keys {','.join(conflicting_keys)} already exists in {destination}. Use --force to overwrite."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
existing_data["auths"].update(new_data["auths"])
|
|
33
|
+
|
|
34
|
+
with open(destination, "w") as f:
|
|
35
|
+
f.write(json.dumps(existing_data))
|
|
36
|
+
else:
|
|
37
|
+
with open(destination, "w") as f:
|
|
38
|
+
f.write(pull_secret)
|
rhdlcli/stats.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_component_size(files):
|
|
7
|
+
size = 0
|
|
8
|
+
for file in files:
|
|
9
|
+
size += file["size"]
|
|
10
|
+
return size
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def enough_space(download_folder, files):
|
|
14
|
+
component_size = get_component_size(files)
|
|
15
|
+
st = os.statvfs(download_folder)
|
|
16
|
+
free_space = st.f_bavail * st.f_frsize * 0.95
|
|
17
|
+
component_size_gb = component_size / 1024 / 1024 / 1024
|
|
18
|
+
free_space_gb = free_space / 1024 / 1024 / 1024
|
|
19
|
+
print("Component size %d GB" % component_size_gb)
|
|
20
|
+
print("Free space %d GB" % free_space_gb)
|
|
21
|
+
return component_size < free_space
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def check_download_folder_has_enough_space(download_folder, files):
|
|
25
|
+
if not enough_space(download_folder, files):
|
|
26
|
+
raise Exception("Not enough space in %s" % download_folder)
|
rhdlcli/validator.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def credentials_are_defined(options):
|
|
8
|
+
required_keys = ["base_url", "access_key", "secret_key"]
|
|
9
|
+
return all(key in options and options[key] is not None for key in required_keys)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def exit_if_credentials_invalid(options):
|
|
13
|
+
if not credentials_are_defined(options):
|
|
14
|
+
print("Credentials are invalid. Run `rhdl login` or set env variables.")
|
|
15
|
+
sys.exit(1)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def destination_folder_exists(options):
|
|
19
|
+
destination = options["destination"]
|
|
20
|
+
if destination and os.path.exists(destination):
|
|
21
|
+
return True
|
|
22
|
+
return False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def exit_if_destination_exists(options):
|
|
26
|
+
if destination_folder_exists(options) and not options["force"]:
|
|
27
|
+
destination = options["destination"]
|
|
28
|
+
print(
|
|
29
|
+
f"Error: Destination folder already exists: {destination}\n"
|
|
30
|
+
f"Use --force to overwrite the existing folder."
|
|
31
|
+
)
|
|
32
|
+
sys.exit(1)
|
rhdlcli/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|