From a3c6eaa2a4bb3873f7e137b48603f9c2c552b39d Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 7 Apr 2023 02:47:32 -0700 Subject: Add sync --upload (mga#2868) This will automatically upload any changed binrepo files and update sha1.lst to match. Using --dryrun will show any changed files but not upload or change anything. --- MgaRepo/binrepo.py | 17 +++++++++++++++++ MgaRepo/commands/sync.py | 6 +++++- MgaRepo/rpmutil.py | 14 +++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'MgaRepo') diff --git a/MgaRepo/binrepo.py b/MgaRepo/binrepo.py index 89679b0..874a091 100644 --- a/MgaRepo/binrepo.py +++ b/MgaRepo/binrepo.py @@ -170,3 +170,20 @@ def update_sources(topdir, added=[], removed=[]): f.write("%s %s\n" % (entries[name], name)) f.close() +def check_sources(topdir): + """Verify hashes against binrepo files + + Returns a list of files that differ. Files have do not exist locally are + ignored. + """ + changed = [] + path = sources_path(topdir) + if os.path.isfile(path): + entries = parse_sources(path) + for filename in entries: + filepath = os.path.join(topdir, 'SOURCES', filename) + if os.path.exists(filepath): + name = os.path.basename(filepath) + if entries[name] != file_hash(filepath): + changed.append(name) + return changed diff --git a/MgaRepo/commands/sync.py b/MgaRepo/commands/sync.py index 54f5635..9f318e1 100644 --- a/MgaRepo/commands/sync.py +++ b/MgaRepo/commands/sync.py @@ -8,12 +8,14 @@ Usage: mgarepo sync Will add or remove from the working copy those files added or removed in the spec file. -It will not commit the changes. +It will not commit the changes, but it will upload or download binrepo files +when -u or -d are given. Options: --dry-run Print results without changing the working copy --download -d Try to download the source files not found + --upload -u Upload changed source files and update sha1.lst -h Show this message Examples: @@ -30,6 +32,8 @@ def parse_options(): action="store_true") parser.add_option("-d", "--download", dest="download", default=False, action="store_true") + parser.add_option("-u", "--upload", dest="up", default=False, + action="store_true") opts, args = parser.parse_args() # TODO: # Completely remove -c switch from code diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py index 66343b5..b71afb0 100644 --- a/MgaRepo/rpmutil.py +++ b/MgaRepo/rpmutil.py @@ -514,7 +514,7 @@ def ispkgtopdir(path=None): names = os.listdir(path) return (".svn" in names and "SPECS" in names and "SOURCES" in names) -def sync(dryrun=False, commit=False, download=False): +def sync(dryrun=False, commit=False, download=False, up=False): svn = SVN() topdir = getpkgtopdir() spath = binrepo.sources_path(topdir) @@ -596,6 +596,18 @@ def sync(dryrun=False, commit=False, download=False): print("A\t%s" % path) if not dryrun: upload([path], commit=commit) + # check binrepo files + changed = binrepo.check_sources(topdir) + if changed: + changed_paths = [] + for filename in changed: + filepath = os.path.join(topdir, 'SOURCES', filename) + changed_paths.append(filepath) + print('M\t%s' % filepath) + if not dryrun and up: + binrepo.upload_binary(topdir, filename) + if not dryrun and up: + binrepo.update_sources(topdir, added=changed_paths) def commit(target=".", message=None, logfile=None): svn = SVN() -- cgit v1.2.1