MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / create_dejacode_package

Function create_dejacode_package

etc/scripts/utils_dejacode.py:161–211  ·  view source on GitHub ↗

Create a new DejaCode Package a Distribution `distribution`. Return the new or existing package data.

(distribution)

Source from the content-addressed store, hash-verified

159
160
161def create_dejacode_package(distribution):
162 """
163 Create a new DejaCode Package a Distribution `distribution`.
164 Return the new or existing package data.
165 """
166 if not can_do_api_calls():
167 return
168
169 existing_package_data = get_package_data(distribution)
170 if existing_package_data:
171 return existing_package_data
172
173 print(f"Creating new DejaCode package for: {distribution}")
174
175 new_package_payload = {
176 # Trigger data collection, scan, and purl
177 "collect_data": 1,
178 }
179
180 fields_to_carry_over = [
181 "download_urltype",
182 "namespace",
183 "name",
184 "version",
185 "qualifiers",
186 "subpath",
187 "license_expression",
188 "copyright",
189 "description",
190 "homepage_url",
191 "primary_language",
192 "notice_text",
193 ]
194
195 for field in fields_to_carry_over:
196 value = getattr(distribution, field, None)
197 if value:
198 new_package_payload[field] = value
199
200 response = requests.post(
201 DEJACODE_API_URL_PACKAGES,
202 data=new_package_payload,
203 headers=DEJACODE_API_HEADERS,
204 timeout=10,
205 )
206 new_package_data = response.json()
207 if response.status_code != 201:
208 raise Exception(f"Error, cannot create package for: {distribution}")
209
210 print(f"New Package created at: {new_package_data['absolute_url']}")
211 return new_package_data

Callers

nothing calls this directly

Calls 3

can_do_api_callsFunction · 0.85
postMethod · 0.80
get_package_dataFunction · 0.70

Tested by

no test coverage detected