~fginther/ubuntu-ci-services-itself/bsbuilder-fixes

« back to all changes in this revision

Viewing changes to branch-source-builder/upload_package.py

  • Committer: Francis Ginther
  • Date: 2014-03-07 18:58:45 UTC
  • Revision ID: francis.ginther@canonical.com-20140307185845-t4onpq5lycgwnxov
Pass subtickets directly to the branch source builder, allowing it to create subticket progress updates that are then updated by the lander. Check contents of the PPAs before uploading to ensure that the build will succeed. Create a results file to pass back as a global result artifact.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        raise EnvironmentError('Failed to open url [{}]: {}'.format(url, e))
65
65
 
66
66
 
67
 
def get_source_files(source_files):
68
 
    location = create_temp_dir()
69
 
    local_files = []
70
 
    for source in source_files:
71
 
        # Co-locate all the files into a temp directory
72
 
        file_name = os.path.basename(source)
73
 
        file_path = os.path.join(location, file_name)
74
 
        logging.info('Retrieving source file: {}'.format(file_name))
75
 
        with open(file_path, 'w') as out_file:
76
 
            out_file.write(get_url_contents(source))
77
 
        local_files.append(file_name)
78
 
    return (location, local_files)
 
67
def get_source_files(subtickets):
 
68
    '''Retrieves the source package files and creates initial upload_list.'''
 
69
    upload_list = []
 
70
    for subticket in subtickets:
 
71
        package = {}
 
72
        spu = subticket['source_package_upload']
 
73
        package['id'] = spu['id']
 
74
        package['name'] = spu['sourcepackage']['name']
 
75
        package['version'] = spu['version']
 
76
        package['resource'] = subticket['resource_uri']
 
77
        package['location'] = create_temp_dir()
 
78
        package['files'] = []
 
79
        for artifact in subticket['artifact']:
 
80
            source = artifact['reference']
 
81
            file_name = os.path.basename(source)
 
82
            file_path = os.path.join(package['location'], file_name)
 
83
            logging.info('Retrieving source file: {}'.format(file_name))
 
84
            with open(file_path, 'w') as out_file:
 
85
                out_file.write(get_url_contents(source))
 
86
            package['files'].append(file_name)
 
87
        upload_list.append(package)
 
88
    return upload_list
79
89
 
80
90
 
81
91
def parse_dsc_file(dsc_file):
87
97
                return arch_lists[0]
88
98
 
89
99
 
90
 
def parse_source_files(source_directory, source_files):
91
 
    package_list = []
92
 
    for source in source_files:
93
 
        source_name = os.path.join(source_directory, source)
94
 
        if source.endswith('changes'):
 
100
def parse_source_files(upload_list):
 
101
    '''Perform a second pass of the upload list and parse out more info.
 
102
 
 
103
    This must be done after all files in a subticket have been acquired.'''
 
104
    for package in upload_list:
 
105
        for source in package['files']:
 
106
            source_name = os.path.join(package['location'], source)
 
107
            if source.endswith('changes'):
95
108
                changes = parse_changes_file(filename=source_name,
96
 
                                             directory=source_directory)
97
 
                package = {}
98
 
                package['name'] = changes.get('Source')
99
 
                package['version'] = changes.get('Version')
100
 
                package['files'] = []
101
 
                package['files'].append(changes.get_changes_file())
 
109
                                             directory=package['location'])
102
110
                for package_file in changes.get_files():
103
111
                    if os.path.exists(package_file):
104
112
                        if package_file.endswith('.dsc'):
105
113
                            package['architecture'] = parse_dsc_file(
106
114
                                package_file)
107
 
                        package['files'].append(package_file)
108
115
                    else:
109
116
                        raise EnvironmentError(
110
117
                            'Not found: {}'.format(package_file))
111
 
                package_list.append(package)
112
 
    return package_list
113
 
 
114
 
 
115
 
def upload_source_packages(ppa, upload_files):
 
118
 
 
119
 
 
120
def upload_source_packages(ppa, subtickets):
116
121
    '''Attempts source file upload into the PPA.'''
117
122
    logging.info('Upload to the ppa: {}'.format(ppa))
118
 
    (source_directory, source_files) = get_source_files(upload_files)
119
 
    source_packages = parse_source_files(source_directory, source_files)
120
 
    for package in source_packages:
 
123
    upload_list = get_source_files(subtickets)
 
124
    parse_source_files(upload_list)
 
125
    for package in upload_list:
121
126
        packagemanager.upload_package(package['name'], package['version'],
122
 
                                      ppa, source_directory)
123
 
    # TODO Return the data set of packages uploaded
124
 
    return source_packages
 
127
                                      ppa, package['location'])
 
128
 
 
129
        directory = package['location']
 
130
        if os.path.exists(directory) and os.path.isdir(directory):
 
131
            logging.info('Removing temp directory: {}'.format(directory))
 
132
            shutil.rmtree(directory)
 
133
 
 
134
    return upload_list
125
135
 
126
136
 
127
137
def main():