def upload_documentation(self, metadata, doc_dir): """ Upload documentation to the index. :param metadata: A :class:`Metadata` instance defining at least a name and version number for the documentation to be uploaded. :param doc_dir: The pathname of the directory which contains the documentation. This should be the directory that contains the ``index.html`` for the documentation. :return: The HTTP response received from PyPI upon submission of the request. """ self.check_credentials() if not os.path.isdir(doc_dir): raise DistlibException('not a directory: %r' % doc_dir) fn = os.path.join(doc_dir, 'index.html') if not os.path.exists(fn): raise DistlibException('not found: %r' % fn) metadata.validate() name, version = metadata.name, metadata.version zip_data = zip_dir(doc_dir).getvalue() fields = [(':action', 'doc_upload'), ('name', name), ('version', version)] files = [('content', name, zip_data)] request = self.encode_request(fields, files) return self.send_request(request)
def check_testdist_available(self): self.index.check_credentials() self.username = self.index.username.replace('-', '_') self.dist_project = '%s_testdist' % self.username self.dist_version = '0.1' self.testdir = '%s-%s' % (self.dist_project, self.dist_version) destdir = os.path.join(HERE, self.testdir) if not os.path.isdir(destdir): # pragma: no cover srcdir = os.path.join(HERE, 'testdist-0.1') shutil.copytree(srcdir, destdir) for fn in os.listdir(destdir): fn = os.path.join(destdir, fn) if os.path.isfile(fn): with codecs.open(fn, 'r', 'utf-8') as f: data = f.read() data = data.format(username=self.username) with codecs.open(fn, 'w', 'utf-8') as f: f.write(data) zip_data = zip_dir(destdir).getvalue() zip_name = destdir + '.zip' with open(zip_name, 'wb') as f: f.write(zip_data)
def test_zip_dir(self): d = os.path.join(HERE, 'foofoo') data = zip_dir(d) self.assertIsInstance(data, BytesIO)