Changeset 6071 in /cluster/svnroot


Ignore:
Timestamp:
Aug 12, 2018 2:24:40 PM (2 years ago)
Author:
skylar
Message:

get dictionary of config data re #915

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar/bccd-3.4.0-build_ng/bin/gen_jenkins_job_xml

    r6067 r6071  
    55import argparse
    66import glob
     7import urllib3
    78import os
     9
     10from bs4 import BeautifulSoup
    811
    912def get_args():
    1013    parser = argparse.ArgumentParser()
    11    
     14
    1215    parser.add_argument('--svn_url', help='URL to SVN branch or tag',required=True,)
    13     parser.add_argument('--stage', help='Branch name (i.e. skylar) or simply "tag" for production build',required=True,)
     16    parser.add_argument('--version', help='BCCD version to build',required=True,)
     17    parser.add_argument('--user', help='Developer user name to include in version tag',required=False,)
    1418    parser.add_argument('--config_dir', help='Directory of Jenkins job configs',required=True,)
    1519    parser.add_argument('--job_dir', help='Jenkins job directory path',required=True,)
     
    1721    return parser.parse_args()
    1822
    19 def get_config_files(config_dir,stage):
    20     """Reads template job files from config_dir, and then returns a list of dictionaries where the key is the input filename"""
    21     """and the value is the output file name (either with the stage name inserted after BCCD-, or kept the same in"""
    22     """the case of the tag stage)."""
    23     return map(lambda f: {os.path.basename(f),os.path.basename(f) if stage=='tag' else os.path.basename(f).replace('BCCD-','BCCD-{}-'.format(stage),1)},
    24             glob.glob(os.path.join(config_dir,'*.xml')))
     23def get_jenkins_project_configs(url):
     24    """Takes in a URL for the Jenkins config directory in SVN, and returns a dictionary of project_name,config_xml_data"""
     25    """Requires each sub-directory of the Jenkins config directory to have a config.xml file"""
     26    http = urllib3.PoolManager()
     27    return {k:v.data for k,v in
     28            {u.strip("/"): http.request('GET', url + '/' + u + '/config.xml')
     29                for u in map(lambda x: x['href'],
     30                    filter(lambda h:
     31                        h['href'] != '../',
     32                        BeautifulSoup(http.request('GET',url).data,'html.parser',).find_all('a',href=True)
     33                        )
     34                    )
     35                }.items() if v.status == 200
     36            }
    2537
    2638def main():
    2739    args = get_args()
    2840
    29     print(list(get_config_files(config_dir=args.config_dir,stage=args.stage)))
     41    print(get_jenkins_project_configs(args.svn_url))
     42
     43    #print(list(get_config_files(
     44    #    config_dir=args.config_dir,
     45    #    version_string='{0}{1}'.format(args.version,'_' + args.user if args.user else '')
     46    #    )))
    3047
    3148if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.