Skip to content

Commit

Permalink
Merge pull request #1399 from dmach/checkout-include-files
Browse files Browse the repository at this point in the history
Implement 'exclude_files' and 'include_files' config options that allow skipping files in the 'checkout' command
  • Loading branch information
dmach authored Aug 30, 2023
2 parents 77152aa + 4255711 commit 4a0c9a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
21 changes: 21 additions & 0 deletions behave/features/checkout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ Scenario: Run `osc checkout` on a package, use a file size limit
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" exists


Scenario: Run `osc checkout` on a package, exclude files
Given I set working directory to "{context.osc.temp}"
When I execute osc with args "checkout test:factory test-pkgA --setopt=exclude_files=*.changes"
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.spec" exists
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist


Scenario: Run `osc checkout` on a package, include files
Given I set working directory to "{context.osc.temp}"
When I execute osc with args "checkout test:factory test-pkgA --setopt=include_files=*.changes"
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.spec" does not exist
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" exists


Scenario: Run `osc checkout` on a package, exclude and include files
Given I set working directory to "{context.osc.temp}"
When I execute osc with args "checkout test:factory test-pkgA --setopt=exclude_files=*.changes --setopt=include_files=*.changes"
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.spec" does not exist
And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist


Scenario: Run `osc checkout` on a package in a specified revision
Given I set working directory to "{context.osc.temp}"
When I execute osc with args "checkout test:factory test-pkgA --revision=2"
Expand Down
4 changes: 4 additions & 0 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def _identify_osccookiejar():
'linkcontrol': '0',
'include_request_from_project': '1',
'local_service_run': '1',
"exclude_files": "",
"include_files": "",

# Maintenance defaults to OBS instance defaults
'maintained_attribute': 'OBS:Maintained',
Expand Down Expand Up @@ -811,6 +813,8 @@ def get_config(override_conffile=None,

re_clist = re.compile('[, ]+')
config['extra-pkgs'] = [i.strip() for i in re_clist.split(config['extra-pkgs'].strip()) if i]
config["exclude_files"] = [i.strip() for i in re_clist.split(config["exclude_files"].strip()) if i]
config["include_files"] = [i.strip() for i in re_clist.split(config["include_files"].strip()) if i]

# collect the usernames, passwords and additional options for each api host
api_host_options = {}
Expand Down
22 changes: 22 additions & 0 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,28 @@ def get_files_meta(self, revision='latest', skip_service=True):
if size and self.size_limit and int(size) > self.size_limit \
or skip_service and (e.get('name').startswith('_service:') or e.get('name').startswith('_service_')):
e.set('skipped', 'true')
continue

if conf.config["exclude_files"]:
exclude = False
for pattern in conf.config["exclude_files"]:
if fnmatch.fnmatch(e.get("name"), pattern):
exclude = True
break
if exclude:
e.set("skipped", "true")
continue

if conf.config["include_files"]:
include = False
for pattern in conf.config["include_files"]:
if fnmatch.fnmatch(e.get("name"), pattern):
include = True
break
if not include:
e.set("skipped", "true")
continue

return ET.tostring(root, encoding=ET_ENCODING)

def get_local_meta(self):
Expand Down

0 comments on commit 4a0c9a0

Please sign in to comment.