def assemble_zip(file_count, force): strio = StringIO.StringIO() for idx in range(file_count): filename = fname(idx) gcs_file = gcs.open(filename, 'r') strio.write(gcs_file.read()) gcs_file.close() export_zip = zipfile.ZipFile(strio) new_export_id = None date_regex = re.compile('Date:\s*(.*)') with export_zip.open('README.md') as readme_file: for line in readme_file: m = date_regex.search(line) if m: new_export_id = m.group(1) if not new_export_id: # TODO: surface error return new_export = WcaExport.get_by_id(new_export_id) or WcaExport(id=new_export_id) if get_latest_export() and new_export.key == get_latest_export().key and not force: # We're trying to reimport the same WCA export. Abort. return new_export.put() sharder.write_sharded_files(export_zip) strio.close() export.process_export(new_export_id)
def get_wca_export(self): return get_latest_export().key.id()