def watermark_install_rdf(self, user): """ Reads the install_rdf out of an addon and writes the user information into it. """ inzip = SafeUnzip(self.file_path) inzip.is_valid() try: install = inzip.extract_path("install.rdf") data = RDF(install) data.set(user.email, self.version.addon.get_watermark_hash(user)) except Exception, e: log.error("Could not alter install.rdf in file: %s for %s, %s" % (self.pk, user.pk, e)) raise
def watermark_install_rdf(self, user): """ Reads the install_rdf out of an addon and writes the user information into it. """ inzip = SafeUnzip(self.file_path) inzip.is_valid() try: install = inzip.extract_path('install.rdf') data = RDF(install) data.set(user.email, self.version.addon.get_watermark_hash(user)) except Exception, e: log.error('Could not alter install.rdf in file: %s for %s, %s' % (self.pk, user.pk, e)) raise
def fix_xpi(xpi, xpi_dir, new_version): with open(os.path.join(xpi_dir, 'install.rdf')) as f: data = RDF(f.read()) parent = (data.dom.documentElement.getElementsByTagName('Description')[0]) for v in parent.getElementsByTagName('em:version'): parent.removeChild(v) v.unlink() elem = data.dom.createElement('em:version') elem.appendChild(data.dom.createTextNode(new_version)) parent.appendChild(elem) # Replace install.rdf: with open(os.path.join(xpi_dir, 'install.rdf'), 'w') as f: f.write(str(data)) wd = os.getcwd() try: os.chdir(xpi_dir) subprocess.check_call(['zip', '-qr', xpi] + os.listdir(os.getcwd())) finally: os.chdir(wd) return path.path(xpi)
def get_rdf(self, tmp): assert tmp unzip = SafeUnzip(tmp) unzip.is_valid() return RDF(unzip.extract_path('install.rdf'))