64
64
raise EnvironmentError('Failed to open url [{}]: {}'.format(url, e))
67
def get_source_files(source_files):
68
location = create_temp_dir()
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.'''
70
for subticket in subtickets:
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()
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)
81
91
def parse_dsc_file(dsc_file):
87
97
return arch_lists[0]
90
def parse_source_files(source_directory, source_files):
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.
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)
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(
107
package['files'].append(package_file)
109
116
raise EnvironmentError(
110
117
'Not found: {}'.format(package_file))
111
package_list.append(package)
115
def upload_source_packages(ppa, upload_files):
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'])
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)