Skip to content

Commit

Permalink
Merge pull request ryanuber#6 from jrwesolo/regex_support
Browse files Browse the repository at this point in the history
add support for regex when matching names
  • Loading branch information
jrwesolo committed Jan 28, 2016
2 parents 03783db + b091a75 commit de69217
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Yumsync CHANGELOG
=================

v0.2.0 (2016-01-28)
-------------------

### Feature

* `--name` now performs matches using regular expressions

### Bugfix

* Running under a TTY and passing `--show` now does not suppress repository list

v0.1.4 (2016-01-27)
-------------------

Expand All @@ -10,16 +21,22 @@ v0.1.4 (2016-01-27)
v0.1.3 (2016-01-26)
-------------------

### Bugfix

* Fix callback function parameters causing `TypeError: start() got an unexpected keyword argument 'filename'`

v0.1.2 (2016-01-21)
-------------------

### Bugfix

* Fix metadata generate for combined metadata (was referencing packages in the versioned directory)

v0.1.1 (2016-01-20)
-------------------

### Bugfix

* Add logic to handle missing config file

v0.1.0 (2016-01-19)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ optional arguments:
defaults to current directory
-c CONFIG, --config CONFIG
Path to YAML config file describing repositories
-n NAME, --name NAME Name of YUM repository (repeatable) from config file
-n NAME, --name NAME Name (regex supported) of YUM repository (repeatable) from config file
to sync instead of all available
-s, --show Only show what repositories would be synced
```
Expand Down
16 changes: 11 additions & 5 deletions bin/yumsync
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from urlparse import urlparse
from urllib2 import urlopen
import argparse
import os
import re
import yumsync
import shutil
import sys
Expand Down Expand Up @@ -181,14 +182,19 @@ def check_cmdline_repos(**rawrepo):
update_repos = {}
if CMDLINEREPOS:
for name in (CMDLINEREPOS):
if name in rawrepo:
update_repos[name] = rawrepo[name]
try:
regex = re.compile(r"{}".format(name), re.IGNORECASE)
for r in [r for r in rawrepo if re.search(regex, r)]:
update_repos[r] = rawrepo[r]
except re.error:
continue
else:
update_repos = rawrepo
log('Repos to sync: %d' % len(update_repos))
log('Repos to sync: %d' % len(update_repos), force=SHOWONLY)
for index, repo in enumerate(sorted(update_repos)):
log('%d) %s' % (index+1, repo))
log('%d) %s' % (index+1, repo), force=SHOWONLY)
if SHOWONLY == True:
log('Exiting without performing changes...', force=SHOWONLY)
sys.exit(0)
return update_repos

Expand Down Expand Up @@ -281,7 +287,7 @@ def print_summary(repos, errors, elapsed):
log('%d %s, %d %s, %s' % (repos, repo_str, errors, error_str, elapsed), header=True)

def main():
log('parsing configuration', header=True)
log('parsing configuration', header=True, force=SHOWONLY)
repo_config = load_config()
repo_config = check_cmdline_repos(**repo_config)

Expand Down
4 changes: 2 additions & 2 deletions yumsync/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

start = int(time.time())

def log(msg, header=False, log_dir=None):
def log(msg, header=False, log_dir=None, force=False):
time_str = time.strftime('%Y-%m-%dT%X%z')
delta = int(time.time()) - start
m, s = divmod(delta, 60)
Expand All @@ -18,7 +18,7 @@ def log(msg, header=False, log_dir=None):
with open(os.path.join(log_dir, 'sync.log'), 'a') as logfile:
logfile.write('{} {}\n'.format(time_str, output_str))

if not sys.__stdout__.isatty():
if force or not sys.__stdout__.isatty():
sys.__stdout__.write('{} {}\n'.format(delta_str, output_str))
sys.__stdout__.flush()

0 comments on commit de69217

Please sign in to comment.