def prepare(self, egg_b64, dest_filename=None): """ validate the egg and process it to prepare for uploading return RegisterModuleUploader object (or None), message """ egg_zip_obj, b64err = zip_of_b64(egg_b64, "python egg") if None is egg_zip_obj: return None, ("Base64 error: %s" % b64err) #validate egg log.debug("validating egg") if not "EGG-INFO/PKG-INFO" in egg_zip_obj.namelist(): return None, "no PKG-INFO found in egg; found %s" % str( egg_zip_obj.namelist()) log.debug("processing driver") pkg_info_data = {} pkg_info = egg_zip_obj.read("EGG-INFO/PKG-INFO") for l in pkg_info.splitlines(): log.debug("Reading %s", l) tmp = l.partition(": ") pkg_info_data[tmp[0]] = tmp[2] for f in ["Name", "Version"]: if not f in pkg_info_data: return None, "Egg's PKG-INFO did not include a field called '%s'" % f #determine egg name dest_filename = "%s-%s-py2.7.egg" % (pkg_info_data["Name"].replace( "-", "_"), pkg_info_data["Version"]) log.info("Egg filename is '%s'", dest_filename) egg_url = self.get_dest_url(dest_filename) log.info("Egg url will be '%s'", egg_url) egg_url_filename = "%s v%s.url" % (pkg_info_data["Name"].replace( "-", "_"), pkg_info_data["Version"]) ret = self.uploader_object_factory(egg_b64, dest_filename) ret.set_egg_urlfile_name(egg_url_filename) return ret, ""
def prepare(self, egg_b64, dest_filename=None): """ validate the egg and process it to prepare for uploading return RegisterModuleUploader object (or None), message """ egg_zip_obj, b64err = zip_of_b64(egg_b64, "python egg") if None is egg_zip_obj: return None, ("Base64 error: %s" % b64err) #validate egg log.debug("validating egg") if not "EGG-INFO/PKG-INFO" in egg_zip_obj.namelist(): return None, "no PKG-INFO found in egg; found %s" % str(egg_zip_obj.namelist()) log.debug("processing driver") pkg_info_data = {} pkg_info = egg_zip_obj.read("EGG-INFO/PKG-INFO") for l in pkg_info.splitlines(): log.debug("Reading %s", l) tmp = l.partition(": ") pkg_info_data[tmp[0]] = tmp[2] for f in ["Name", "Version"]: if not f in pkg_info_data: return None, "Egg's PKG-INFO did not include a field called '%s'" % f #determine egg name dest_filename = "%s-%s-py2.7.egg" % (pkg_info_data["Name"].replace("-", "_"), pkg_info_data["Version"]) log.info("Egg filename is '%s'", dest_filename) egg_url = self.get_dest_url(dest_filename) log.info("Egg url will be '%s'", egg_url) egg_url_filename = "%s v%s.url" % (pkg_info_data["Name"].replace("-", "_"), pkg_info_data["Version"]) ret = self.uploader_object_factory(egg_b64, dest_filename) ret.set_egg_urlfile_name(egg_url_filename) return ret, ""
def prepare(self, qa_documents_zip_b64): self.csv_reader = None self.qa_zip_obj = None qa_zip_obj, b64err = zip_of_b64(qa_documents_zip_b64, "qa_documents") if None is qa_zip_obj: return False, ("Base64 error: %s" % b64err) #parse the manifest file if not QA_DOCS_MANIFEST_FILE in qa_zip_obj.namelist(): return False, ("provided qa_documents zipfile lacks manifest CSV file called %s" % QA_DOCS_MANIFEST_FILE) log.debug("extracting manifest csv file") csv_contents = qa_zip_obj.read(QA_DOCS_MANIFEST_FILE) log.debug("parsing manifest csv file") try: dialect = csv.Sniffer().sniff(csv_contents) except csv.Error: dialect = csv.excel except Exception as e: return False, ("%s - %s", str(type(e)), str(e.args)) csv_reader = csv.DictReader(StringIO(csv_contents), dialect=dialect) #validate fields in manifest file log.debug("validing manifest csv file") for f in ["filename", "name", "description", "content_type", "keywords"]: if not f in csv_reader.fieldnames: return False, ("Manifest file %s missing required field %s" % (QA_DOCS_MANIFEST_FILE, f)) self.csv_reader = csv_reader self.qa_zip_obj = qa_zip_obj return True, ""