Skip to content

Commit 3b01c28

Browse files
committed
Remove logging and messaging #116
Reference: #116 Signed-off-by: John M. Horan <johnmhoran@gmail.com>
1 parent 801e740 commit 3b01c28

10 files changed

+575
-527
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ install_requires =
5959
requests
6060
python-dateutil
6161
python-dotenv
62-
univers == 30.11.0
62+
univers >= 30.11.0
6363

6464

6565
[options.packages.find]

src/fetchcode/package.py

Lines changed: 19 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations under the License.
1616

1717
import dataclasses
18-
import logging
19-
import os
2018
import re
2119
import time
2220
from typing import List
@@ -36,17 +34,12 @@
3634
from fetchcode.package_util import OpenSSLGitHubSource
3735
from fetchcode.package_util import construct_cocoapods_package
3836
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
4137
from fetchcode.packagedcode_models import Package
4238
from fetchcode.utils import get_hashed_path
4339
from fetchcode.utils import get_response
4440

4541
router = Router()
4642

47-
LOG_FILE_LOCATION = os.path.join(os.path.expanduser("~"), "purlcli.log")
48-
logger = logging.getLogger(__name__)
49-
5043

5144
def info(url):
5245
"""
@@ -374,113 +367,40 @@ def get_gnu_data_from_purl(purl):
374367

375368
@router.route("pkg:cocoapods/.*")
376369
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-
387370
purl = PackageURL.from_string(purl)
388371
name = purl.name
389-
version = purl.version
390372
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-
463373
api = "https://cdn.cocoapods.org"
464-
hashed_path = get_hashed_path(cocoapods_org_pod_name)
374+
hashed_path = get_hashed_path(name)
465375
hashed_path_underscore = hashed_path.replace("/", "_")
466376
file_prefix = "all_pods_versions_"
467377
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+
471380
for tag in data_list:
472381
if purl.version and tag != purl.version:
473382
continue
474383

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+
475396
tag_pkg = construct_cocoapods_package(
476397
purl,
477398
name,
478399
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
484404
)
485405

486406
yield tag_pkg

0 commit comments

Comments
 (0)