Refactor conditional_PUT as core function

Introduce source_file_ensure in osclib.core following review in #1717
This commit is contained in:
Stephan Kulow 2018-10-03 07:36:42 +02:00
parent 2d4148f3f2
commit c4fa49aef2
2 changed files with 7 additions and 14 deletions

View File

@ -265,6 +265,10 @@ def source_file_save(apiurl, project, package, filename, content, comment=None):
url = makeurl(apiurl, ['source', project, package, filename], {'comment': comment}) url = makeurl(apiurl, ['source', project, package, filename], {'comment': comment})
http_PUT(url, data=content) http_PUT(url, data=content)
def source_file_ensure(apiurl, project, package, filename, content, comment=None):
if content != source_file_load(apiurl, project, package, filename):
source_file_save(apiurl, project, package, filename, content, comment)
def project_pseudometa_package(apiurl, project): def project_pseudometa_package(apiurl, project):
package = Config.get(apiurl, project).get('pseudometa_package', '00Meta') package = Config.get(apiurl, project).get('pseudometa_package', '00Meta')
if '/' in package: if '/' in package:

View File

@ -24,6 +24,7 @@ from osclib.cache_manager import CacheManager
from osclib.conf import Config, str2bool from osclib.conf import Config, str2bool
from osclib.core import repository_path_expand from osclib.core import repository_path_expand
from osclib.core import repository_arch_state from osclib.core import repository_arch_state
from osclib.core import source_file_ensure
from osclib.stagingapi import StagingAPI from osclib.stagingapi import StagingAPI
from osclib.util import project_list_family from osclib.util import project_list_family
from osclib.util import project_list_family_prior from osclib.util import project_list_family_prior
@ -1383,21 +1384,9 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
for package in sorted(summary[group]): for package in sorted(summary[group]):
summary_str += " - " + package + "\n" summary_str += " - " + package + "\n"
url = api.makeurl(['source', opts.project, '000product-summary', 'summary.yml']) source_file_ensure(api.apiurl, opts.project, '000product-summary', 'summary.yml', summary_str, 'Updating summary.yml')
self.conditional_PUT(url, summary_str)
unsorted_yml = open(os.path.join(product_dir, 'unsorted.yml')).read() unsorted_yml = open(os.path.join(product_dir, 'unsorted.yml')).read()
url = api.makeurl(['source', opts.project, '000product-summary', 'unsorted.yml']) source_file_ensure(api.apiurl, opts.project, '000product-summary', 'unsorted.yml', summary_str, 'Updating unsorted.yml')
self.conditional_PUT(url, unsorted_yml)
def conditional_PUT(self, url, data):
try:
olddata = http_GET(url).read()
if olddata == data:
return
except HTTPError:
pass
http_PUT(url, data=data)
def solv_cache_update(self, apiurl, cache_dir_solv, target_project, family_last, family_include, opts): def solv_cache_update(self, apiurl, cache_dir_solv, target_project, family_last, family_include, opts):
"""Dump solv files (do_dump_solv) for all products in family.""" """Dump solv files (do_dump_solv) for all products in family."""