Skip to content

Commit

Permalink
parser: add use-url-name option ...
Browse files Browse the repository at this point in the history
... so that acbs will rename the source file to the apparent URL file
name
  • Loading branch information
liushuyu committed Dec 5, 2023
1 parent 4ea4619 commit 4a32966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions acbs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, type: str, url: str, revision=None, branch=None, depth=None)
self.depth: Optional[int] = depth
self.chksum: Tuple[str, str] = ('', '')
self.source_name: Optional[str] = ''
self.use_url_name: bool = False
# where the source file/folder is located (on local filesystem)
self.source_location: Optional[str] = None
self.enabled: bool = True
Expand Down
8 changes: 8 additions & 0 deletions acbs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from collections import OrderedDict
from typing import Dict, List, Optional
from urllib.parse import urlparse

from acbs import bashvar
from acbs.base import ACBSPackageInfo, ACBSSourceInfo
Expand Down Expand Up @@ -51,6 +52,11 @@ def parse_url_schema(url: str, checksum: str) -> ACBSSourceInfo:
acbs_source_info.chksum = (
chksum_[0], chksum_[1]) if checksum != 'SKIP' else ('none', '')
acbs_source_info.url = url_plain
if acbs_source_info.use_url_name and acbs_source_info.source_name:
raise ValueError("Option 'use-url-name' can NOT be used with the 'rename' option.")
if acbs_source_info.use_url_name:
parsed = urlparse(url_plain)
acbs_source_info.source_name = os.path.basename(parsed.path)
return acbs_source_info


Expand All @@ -62,6 +68,8 @@ def parse_fetch_options(options: str, acbs_source_info: ACBSSourceInfo):
acbs_source_info.branch = v.strip()
elif k == 'rename':
acbs_source_info.source_name = v.strip()
elif k == 'use-url-name':
acbs_source_info.use_url_name = v.strip() == 'true'
elif k == 'commit':
acbs_source_info.revision = v.strip()
elif k == 'copy-repo':
Expand Down

0 comments on commit 4a32966

Please sign in to comment.