spec_file = each_line.split('"build ')[1].split('.spec')[0]
return spec_file
+def replace_predefined_val_from_file_content_in_name(name,file_contents):
+ print 'replace_predefined_val_from_file_content_in_name for name: %s' %name
+
+ def_list=name.split('%{')[1:]
+ for each_def in def_list:
+ each_def=each_def.split('}')[0]
+ each_def_val=file_contents.split(each_def)[1].split('\n')[0].replace('"','').replace("'",'').replace(' ','')
+ name = name.replace('%{'+each_def+'}',each_def_val)
+
+ return name
+
class GBSBuild:
"""A class which supports with statement"""
- def __init__(self, gbsbuild_tag, obs_prj, basic_url, snapshot_num, trigger_category, new_pkg_list, rm_pkg_list, rm_from_img_list, gbsbuild_workspace):
+ def __init__(self, gbsbuild_tag, obs_prj, basic_url, snapshot_num, trigger_category, new_pkg_list, rm_pkg_list, rm_from_img_list, add_to_img_list, gbsbuild_workspace):
""" Initialize GBSBuild class"""
print "-----------------------------------------------------"
print "Initialize GBS Build Class"
self.gbsbuild_tag = gbsbuild_tag
self.trigger_category = trigger_category
self.aggregate_list = aggregate_list
+ self.rm_from_img_list = rm_from_img_list
+ self.add_to_img_list = add_to_img_list
print 'profile: %s,obs_prj: %s,t_ver: %s,t_ver_path: %s,t_branch: %s,\
basic_snapshot_url: %s,snapshot_num: %s,snapshot_url: %s,snapshot_build_id: %s,\
- repository: %s,arch_list: %s, path_prj_list: %s,prj_src_root: %s\
- build_root: %s, basic_url: %s, is_fullbuild: %s, build_pkg_list: %s\
- trigger_category: %s, gbsbuild_workspace: %s, aggregate_list: %s'\
+ repository: %s,arch_list: %s, path_prj_list: %s,prj_src_root: %s,\
+ build_root: %s, basic_url: %s, is_fullbuild: %s, build_pkg_list: %s,\
+ trigger_category: %s, gbsbuild_workspace: %s, aggregate_list: %s,\
+ rm_from_img_list: %s, add_to_img_list: %s'\
%(profile,obs_prj,t_ver,t_ver_path,t_branch,basic_snapshot_url,snapshot_num,\
snapshot_url,snapshot_build_id,repository,arch_list,path_prj_list,prj_src_root,\
build_root,basic_url,is_fullbuild,build_pkg_list,trigger_category,\
- gbsbuild_workspace,aggregate_list)
+ gbsbuild_workspace,aggregate_list,rm_from_img_list,add_to_img_list)
def convert_gbsbuild_to_dictionary(self):
dic = {}
dic['gbsbuild_tag'] = self.gbsbuild_tag
dic['trigger_category'] = self.trigger_category
dic['aggregate_list'] = self.aggregate_list
-
+ dic['rm_from_img_list'] = self.rm_from_img_list
+ dic['add_to_img_list'] = self.add_to_img_list
return dic
def get_build_pkg_data(self):
%(git_name,git_name,build_pkg_list_replace[git_name])
break
- rm_pkg_found = 'false'
- for git_name in self.rm_pkg_list_array:
- if each_line.find(git_name) != -1:
- rm_pkg_found = 'true'
- break
+# rm_pkg will be removed after repo sync
+# rm_pkg_found = 'false'
+# for git_name in self.rm_pkg_list_array:
+# if each_line.find(git_name) != -1:
+# rm_pkg_found = 'true'
+# break
#if rm package is found in manifest file, don't perform adding each_line to manifest file
- if rm_pkg_found == 'true':
- continue
+# if rm_pkg_found == 'true':
+# continue
if each_line.find('</manifest>') != -1:
continue
f.write(gbs_conf_text)
f.close()
+ def __rm_rpm_from_meta_git(self,repo):
+ print '----start __rm_rpm_from_meta_git-----------------------------------'
+ src_path = os.path.join(self.prj_src_root,repo)
+ rm_rpms_from_img = []
+
+ for git_name in self.rm_from_img_list.split(' '):
+ for each_file in os.listdir(os.path.join(src_path,git_name,'packaging')):
+ if each_file.endswith('.spec'):
+ spec_file=os.path.join(src_path,git_name,'packaging',each_file)
+ with open(spec_file,"rb") as f:
+ file_contents = f.read()
+ for line in file_contents.split('\n'):
+ if line.find('Name:') != -1:
+ orig_rpm_name = line.split('Name:')[1].replace(' ','').replace('\t','')
+ #When pre-defined value is used in 'Name' filed
+ if orig_rpm_name.find('%{') != -1:
+ orig_rpm_name = replace_predefined_val_from_file_content_in_name(orig_rpm_name,file_contents)
+ rm_rpms_from_img.append(orig_rpm_name)
+ if line.find('%package') != -1:
+ sub_pkg_post_name = line.split('%package')[1].replace(' ','').replace('\t','')
+ if sub_pkg_post_name.find('%{') != -1:
+ sub_pkg_post_name = replace_predefined_val_from_file_content_in_name(sub_pkg_post_name,file_contents)
+ rm_rpms_from_img.append(orig_rpm_name+'-'+sub_pkg_post_name)
+ print 'Remove rpm list from image: %s' %rm_rpms_from_img
+
+ cmd = 'find '+src_path+' -name patterns | grep meta'
+ result = subprocess.check_output(cmd,shell=True)
+
+ for each_dir in result.split('\n'):
+ print 'meta dir name: %s' %each_dir
+ if not os.path.exists(each_dir):
+ continue
+ for each_file in os.listdir(each_dir):
+ if each_file.endswith('.yaml'):
+ each_file_path=os.path.join(src_path,each_dir,each_file)
+ with open(each_file_path,"rb") as f:
+ file_content=f.read()
+ file_content_orig=file_content
+ for rpm_name in rm_rpms_from_img:
+ file_content=file_content.replace('- '+rpm_name+'\n','')
+ if file_content != file_content_orig:
+ print "file: %s is modified in the process of remove rpms from image" %each_file_path
+ with open(each_file_path,"wb") as f2:
+ f2.write(each_file_path)
+
+
+ def __add_rpm_to_meta_git(self,repo):
+ print '----start __add_rpm_to_meta_git-----------------------------------'
+ src_path = os.path.join(self.prj_src_root,repo)
+
+ for add_pkg in self.add_to_img_list:
+ #find .yaml file path
+ cmd = 'find '+src_path+' -name "'+add_pkg['pattern_name'] +'.yaml" | grep patterns'
+ result = subprocess.check_output(cmd,shell=True)
+ meta_file_path=result.split('\n')[0]
+ print '%s is added to %s' %(add_pkg['rpm_name'], meta_file_path)
+ #add rpm name to *.yaml file
+ with open(meta_file_path,"rb") as f:
+ file_content=f.read()
+ if not file_content.endswith('\n'):
+ file_content += '\n'
+ file_content = file_content + '- ' +add_pkg['rpm_name']
+ with open(meta_file_path,"wb") as f2:
+ f2.write(file_content)
+
+
+ def __rm_git_from_build_src(self,repo):
+ print '----start __rm_git_from_build_src-----------------------------------'
+ src_path = os.path.join(self.prj_src_root,repo)
+
+ for rm_git in self.rm_pkg_list_array:
+ cmd = 'sudo rm -rf '+os.path.join(src_path,rm_git)
+ print 'Remove git %s from build source with cmd: %s' %(rm_git,cmd)
+ subprocess.call(cmd, stdout=sys.stdout,stderr=sys.stderr, shell=True)
+
def _get_gbs_build_result_status(self,repo,arch):
print '----start _get_gbs_build_result_status-----------------------------------'
cmd = 'sudo rm -rf '+repo_init_clear_files
subprocess.call(cmd, stdout=sys.stdout,stderr=sys.stderr, shell=True)
+ # rm meta git, because they can have un-commited changes from previous gbs build
+ cmd = 'find '+repo_src_root+' -name patterns | grep meta'
+ try:
+ result = subprocess.check_output(cmd,shell=True)
+ result = result.replace('/patterns\n','\n')
+ for meta_git in result.split('\n'):
+ if meta_git:
+ print 'remove meta_git: %s for next gbs build' %meta_git
+ cmd = 'sudo rm -rf '+meta_git
+ subprocess.call(cmd, stdout=sys.stdout,stderr=sys.stderr, shell=True)
+ except:
+ print "There is no meta git"
+
#add '-u' option
repo_init_arg = ' -u ssh://%s:%s/scm/manifest' %(os.getenv('GERRIT_HOSTNAME_EXTERNAL'),
# repo_init_arg = ' -u ssh://%s:%s/scm/manifest' %(os.getenv('PUBLIC_GERRIT_HOSTNAME'),
self.__update_gbs_conf_for_one_profile_repo(repo)
+ if self.rm_from_img_list:
+ self.__rm_rpm_from_meta_git(repo)
+ if self.add_to_img_list:
+ self.__add_rpm_to_meta_git(repo)
+ if self.rm_pkg_list_array:
+ self.__rm_git_from_build_src(repo)
+
repo_init_sync_status = 'S'
status_reason = 'Succeeded'
+
return (repo_init_sync_status, status_reason)
return binary_list
- def _do_repo_arch_gbs_fullbuild(self,repo,arch):
+ def _do_repo_arch_gbs_fullbuild(self,repo,arch,gbs_build_arg=None):
print '----start _do_repo_arch_gbs_fullbuild-----------------------------------'
- gbs_default_build_arg='timeout 6h gbs build --threads=16 --define "jobs 8" --define "_smp_mflags -j8" --baselibs --clean-once'
+ if not gbs_build_arg:
+ gbs_default_build_arg='timeout 6h gbs build --threads=16 --define "jobs 8" --define "_smp_mflags -j8" --baselibs --clean-once --include-all'
+ else:
+ gbs_default_build_arg='timeout 6h gbs build '+gbs_build_arg
#add arch
gbs_build_arg = ' -A '+arch