|
15 | 15 | # specific language governing permissions and limitations under the License. |
16 | 16 |
|
17 | 17 | import dataclasses |
18 | | -import logging |
19 | | -import os |
20 | 18 | import re |
21 | 19 | import time |
22 | 20 | from typing import List |
|
36 | 34 | from fetchcode.package_util import OpenSSLGitHubSource |
37 | 35 | from fetchcode.package_util import construct_cocoapods_package |
38 | 36 | from fetchcode.package_util import get_cocoapod_tags |
39 | | -from fetchcode.package_util import get_cocoapods_org_url_status |
40 | | -from fetchcode.package_util import get_pod_data_with_soup |
41 | 37 | from fetchcode.packagedcode_models import Package |
42 | 38 | from fetchcode.utils import get_hashed_path |
43 | 39 | from fetchcode.utils import get_response |
44 | 40 |
|
45 | 41 | router = Router() |
46 | 42 |
|
47 | | -LOG_FILE_LOCATION = os.path.join(os.path.expanduser("~"), "purlcli.log") |
48 | | -logger = logging.getLogger(__name__) |
49 | | - |
50 | 43 |
|
51 | 44 | def info(url): |
52 | 45 | """ |
@@ -374,113 +367,40 @@ def get_gnu_data_from_purl(purl): |
374 | 367 |
|
375 | 368 | @router.route("pkg:cocoapods/.*") |
376 | 369 | def get_cocoapods_data_from_purl(purl): |
377 | | - """ |
378 | | - Generate `Package` object from the `purl` string of cocoapods type |
379 | | - """ |
380 | | - logging.basicConfig( |
381 | | - filename=LOG_FILE_LOCATION, |
382 | | - level=logging.WARN, |
383 | | - format="%(levelname)s - %(message)s", |
384 | | - filemode="w", |
385 | | - ) |
386 | | - |
387 | 370 | purl = PackageURL.from_string(purl) |
388 | 371 | name = purl.name |
389 | | - version = purl.version |
390 | 372 | cocoapods_org_url = f"https://cocoapods.org/pods/{name}" |
391 | | - repository_homepage_url = f"https://cocoapods.org/pods/{name}" |
392 | | - |
393 | | - purl_to_cocoapods_org_url_status = get_cocoapods_org_url_status(purl, name, cocoapods_org_url) |
394 | | - cocoa_org_url_status = purl_to_cocoapods_org_url_status["return_message"] |
395 | | - |
396 | | - status_values = [ |
397 | | - "cocoapods_org_redirects_to_github", |
398 | | - "cocoapods_org_url_redirects", |
399 | | - "failed_to_fetch_github_redirect", |
400 | | - "github_redirect_error", |
401 | | - "github_redirect_not_found", |
402 | | - ] |
403 | | - |
404 | | - cocoa_org_url_status_code = None |
405 | | - if cocoa_org_url_status == "cocoapods_org_url_not_found": |
406 | | - cocoa_org_url_status_code = 404 |
407 | | - elif cocoa_org_url_status == "cocoapods_org_url_temporarily_unavailable": |
408 | | - cocoa_org_url_status_code = 503 |
409 | | - elif any(cocoa_org_url_status == status for status in status_values): |
410 | | - cocoa_org_url_status_code = 302 |
411 | | - |
412 | | - if ( |
413 | | - cocoa_org_url_status == "cocoapods_org_url_not_found" |
414 | | - or cocoa_org_url_status == "cocoapods_org_url_redirects" |
415 | | - or cocoa_org_url_status == "cocoapods_org_url_temporarily_unavailable" |
416 | | - or cocoa_org_url_status == "failed_to_fetch_github_redirect" |
417 | | - or cocoa_org_url_status == "github_redirect_error" |
418 | | - or cocoa_org_url_status == "github_redirect_not_found" |
419 | | - ): |
420 | | - return |
421 | | - |
422 | | - purl_to_pod_data_with_soup = {} |
423 | | - if cocoa_org_url_status_code != 302 and cocoa_org_url_status_code != 503: |
424 | | - purl_to_pod_data_with_soup = get_pod_data_with_soup(purl, name, cocoapods_org_url) |
425 | | - |
426 | | - cocoapods_org_pod_name = None |
427 | | - if purl_to_pod_data_with_soup.get('cocoapods_org_pod_name') is not None: |
428 | | - cocoapods_org_pod_name = purl_to_pod_data_with_soup["cocoapods_org_pod_name"] |
429 | | - elif purl_to_cocoapods_org_url_status.get('cocoapods_org_pod_name') is not None: |
430 | | - cocoapods_org_pod_name = purl_to_cocoapods_org_url_status["cocoapods_org_pod_name"] |
431 | | - |
432 | | - cocoapods_org_version = None |
433 | | - cocoapods_org_gh_repo_owner = None |
434 | | - cocoapods_org_gh_repo_name = None |
435 | | - |
436 | | - if purl_to_pod_data_with_soup.get("cocoapods_org_version") is not None: |
437 | | - cocoapods_org_version = purl_to_pod_data_with_soup["cocoapods_org_version"] |
438 | | - elif purl_to_cocoapods_org_url_status.get("cocoapods_org_version") is not None: |
439 | | - cocoapods_org_version = purl_to_cocoapods_org_url_status[ |
440 | | - "cocoapods_org_version" |
441 | | - ] |
442 | | - |
443 | | - if purl_to_pod_data_with_soup.get("cocoapods_org_gh_repo_owner") is not None: |
444 | | - cocoapods_org_gh_repo_owner = purl_to_pod_data_with_soup[ |
445 | | - "cocoapods_org_gh_repo_owner" |
446 | | - ] |
447 | | - elif ( |
448 | | - purl_to_cocoapods_org_url_status.get("cocoapods_org_gh_repo_owner") is not None |
449 | | - ): |
450 | | - cocoapods_org_gh_repo_owner = purl_to_cocoapods_org_url_status[ |
451 | | - "cocoapods_org_gh_repo_owner" |
452 | | - ] |
453 | | - |
454 | | - if purl_to_pod_data_with_soup.get("cocoapods_org_gh_repo_name") is not None: |
455 | | - cocoapods_org_gh_repo_name = purl_to_pod_data_with_soup[ |
456 | | - "cocoapods_org_gh_repo_name" |
457 | | - ] |
458 | | - elif purl_to_cocoapods_org_url_status.get("cocoapods_org_gh_repo_name") is not None: |
459 | | - cocoapods_org_gh_repo_name = purl_to_cocoapods_org_url_status[ |
460 | | - "cocoapods_org_gh_repo_name" |
461 | | - ] |
462 | | - |
463 | 373 | api = "https://cdn.cocoapods.org" |
464 | | - hashed_path = get_hashed_path(cocoapods_org_pod_name) |
| 374 | + hashed_path = get_hashed_path(name) |
465 | 375 | hashed_path_underscore = hashed_path.replace("/", "_") |
466 | 376 | file_prefix = "all_pods_versions_" |
467 | 377 | spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt" |
468 | | - data_list = get_cocoapod_tags(spec, cocoapods_org_pod_name) |
469 | | - if not version: |
470 | | - version = cocoapods_org_version |
| 378 | + data_list = get_cocoapod_tags(spec, name) |
| 379 | + |
471 | 380 | for tag in data_list: |
472 | 381 | if purl.version and tag != purl.version: |
473 | 382 | continue |
474 | 383 |
|
| 384 | + gh_repo_owner = None |
| 385 | + gh_repo_name = name |
| 386 | + podspec_api_url = f"https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/{hashed_path}/{name}/{tag}/{name}.podspec.json" |
| 387 | + podspec_api_response = get_response(podspec_api_url) |
| 388 | + podspec_homepage = podspec_api_response.get('homepage') |
| 389 | + |
| 390 | + if podspec_homepage.startswith("https://github.com/"): |
| 391 | + podspec_homepage_remove_gh_prefix = podspec_homepage.replace("https://github.com/", "") |
| 392 | + podspec_homepage_split = podspec_homepage_remove_gh_prefix.split("/") |
| 393 | + gh_repo_owner = podspec_homepage_split[0] |
| 394 | + gh_repo_name = podspec_homepage_split[-1] |
| 395 | + |
475 | 396 | tag_pkg = construct_cocoapods_package( |
476 | 397 | purl, |
477 | 398 | name, |
478 | 399 | hashed_path, |
479 | | - repository_homepage_url, |
480 | | - cocoapods_org_gh_repo_owner, |
481 | | - cocoapods_org_gh_repo_name, |
482 | | - tag, |
483 | | - cocoapods_org_pod_name |
| 400 | + cocoapods_org_url, |
| 401 | + gh_repo_owner, |
| 402 | + gh_repo_name, |
| 403 | + tag |
484 | 404 | ) |
485 | 405 |
|
486 | 406 | yield tag_pkg |
|
0 commit comments