Example #1
0
	def main(self, args):
		"""
		Build all release tarballs.

		@type args: list of str
		@param args: The command line arguments to process.  This must contain
			two strings: the checkout directory and the destination directory.
		"""
		if len(args) != 2:
			sys.exit("Must specify two arguments: "
					 "Twisted checkout and destination path")
		self.buildAllTarballs(FilePath(args[0]), FilePath(args[1]))
Example #2
0
	def main(self, args):
		"""
		Build API documentation.

		@type args: list of str
		@param args: The command line arguments to process.  This must contain
			two strings: the path to the root of the Twisted checkout, and a
			path to an output directory.
		"""
		if len(args) != 2:
			sys.exit("Must specify two arguments: "
					 "Twisted checkout and destination path")
		self.buildAPIDocs(FilePath(args[0]), FilePath(args[1]))
Example #3
0
	def buildPDF(self, bookPath, inputDirectory, outputPath):
		"""
		Build a PDF from the given a LaTeX book document.

		@type bookPath: L{FilePath}
		@param bookPath: The location of a LaTeX document defining a book.

		@type inputDirectory: L{FilePath}
		@param inputDirectory: The directory which the inputs of the book are
			relative to.

		@type outputPath: L{FilePath}
		@param outputPath: The location to which to write the resulting book.
		"""
		if not bookPath.basename().endswith(".tex"):
			raise ValueError("Book filename must end with .tex")

		workPath = FilePath(mkdtemp())
		try:
			startDir = os.getcwd()
			try:
				os.chdir(inputDirectory.path)

				texToDVI = [
					"latex", "-interaction=nonstopmode",
					"-output-directory=" + workPath.path,
					bookPath.path]

				# What I tell you three times is true!
				# The first two invocations of latex on the book file allows it
				# correctly create page numbers for in-text references.  Why this is
				# the case, I could not tell you. -exarkun
				for i in range(3):
					self.run(texToDVI)

				bookBaseWithoutExtension = bookPath.basename()[:-4]
				dviPath = workPath.child(bookBaseWithoutExtension + ".dvi")
				psPath = workPath.child(bookBaseWithoutExtension + ".ps")
				pdfPath = workPath.child(bookBaseWithoutExtension + ".pdf")
				self.run([
					"dvips", "-o", psPath.path, "-t", "letter", "-Ppdf",
					dviPath.path])
				self.run(["ps2pdf13", psPath.path, pdfPath.path])
				pdfPath.moveTo(outputPath)
				workPath.remove()
			finally:
				os.chdir(startDir)
		except:
			workPath.moveTo(bookPath.parent().child(workPath.basename()))
			raise
Example #4
0
def _parseClientSSL(**kwargs):
	"""
	Perform any argument value coercion necessary for SSL client parameters.

	Valid keyword arguments to this function are all L{IReactorSSL.connectSSL}
	arguments except for C{contextFactory}.  Instead, C{certKey} (the path name
	of the certificate file) C{privateKey} (the path name of the private key
	associated with the certificate) are accepted and used to construct a
	context factory.
	
	@param caCertsDir: The one parameter which is not part of
		L{IReactorSSL.connectSSL}'s signature, this is a path name used to
		construct a list of certificate authority certificates.  The directory
		will be scanned for files ending in C{.pem}, all of which will be
		considered valid certificate authorities for this connection.

	@type caCertsDir: C{str}

	@return: The coerced values as a C{dict}.
	"""
	from lib.twisted.internet import ssl
	kwargs = _parseClientTCP(**kwargs)
	certKey = kwargs.pop('certKey', None)
	privateKey = kwargs.pop('privateKey', None)
	caCertsDir = kwargs.pop('caCertsDir', None)
	if certKey is not None:
		certx509 = ssl.Certificate.loadPEM(
			FilePath(certKey).getContent()).original
	else:
		certx509 = None
	if privateKey is not None:
		privateKey = ssl.PrivateCertificate.loadPEM(
			FilePath(privateKey).getContent()).privateKey.original
	else:
		privateKey = None
	if caCertsDir is not None:
		verify = True
		caCerts = _loadCAsFromDir(FilePath(caCertsDir))
	else:
		verify = False
		caCerts = None
	kwargs['sslContextFactory'] = ssl.CertificateOptions(
		method=ssl.SSL.SSLv23_METHOD,
		certificate=certx509,
		privateKey=privateKey,
		verify=verify,
		caCerts=caCerts
	)
	return kwargs
Example #5
0
def buildAllTarballs(checkout, destination):
	"""
	Build complete tarballs (including documentation) for Twisted and all
	subprojects.

	This should be called after the version numbers have been updated and
	NEWS files created.

	@type checkout: L{FilePath}
	@param checkout: The SVN working copy from which a pristine source tree
		will be exported.
	@type destination: L{FilePath}
	@param destination: The directory in which tarballs will be placed.

	@raise UncleanWorkingDirectory: if there are modifications to the
		working directory of C{checkout}.
	@raise NotWorkingDirectory: if the checkout path is not an SVN checkout.
	"""
	if not checkout.child(".svn").exists():
		raise NotWorkingDirectory(
			"%s does not appear to be an SVN working directory."
			% (checkout.path,))
	if runCommand(["svn", "st", checkout.path]).strip():
		raise UncleanWorkingDirectory(
			"There are local modifications to the SVN checkout in %s."
			 % (checkout.path,))

	workPath = FilePath(mkdtemp())
	export = workPath.child("export")
	runCommand(["svn", "export", checkout.path, export.path])
	twistedPath = export.child("twisted")
	version = Project(twistedPath).getVersion()
	versionString = version.base()

	apiBaseURL = "http://twistedmatrix.com/documents/%s/api/%%s.html" % (
		versionString)
	if not destination.exists():
		destination.createDirectory()
	db = DistributionBuilder(export, destination, apiBaseURL=apiBaseURL)

	db.buildCore(versionString)
	for subproject in twisted_subprojects:
		if (subproject not in db.blacklist
			and twistedPath.child(subproject).exists()):
			db.buildSubProject(subproject, versionString)

	db.buildTwisted(versionString)
	workPath.remove()
Example #6
0
    def _findEntryPathString(self, modobj):
        """
		Determine where a given Python module object came from by looking at path
		entries.
		"""
        topPackageObj = modobj
        while '.' in topPackageObj.__name__:
            topPackageObj = self.moduleDict['.'.join(
                topPackageObj.__name__.split('.')[:-1])]
        if _isPackagePath(FilePath(topPackageObj.__file__)):
            # if package 'foo' is on sys.path at /a/b/foo, package 'foo's
            # __file__ will be /a/b/foo/__init__.py, and we are looking for
            # /a/b here, the path-entry; so go up two steps.
            rval = dirname(dirname(topPackageObj.__file__))
        else:
            # the module is completely top-level, not within any packages.  The
            # path entry it's on is just its dirname.
            rval = dirname(topPackageObj.__file__)

        # There are probably some awful tricks that an importer could pull
        # which would break this, so let's just make sure... it's a loaded
        # module after all, which means that its path MUST be in
        # path_importer_cache according to PEP 302 -glyph
        if rval not in self.importerCache:
            warnings.warn(
                "%s (for module %s) not in path importer cache "
                "(PEP 302 violation - check your local configuration)." %
                (rval, modobj.__name__),
                stacklevel=3)

        return rval
Example #7
0
	def main(self, args):
		"""
		Given a list of command-line arguments, change all the Twisted versions
		in the current directory.

		@type args: list of str
		@param args: List of command line arguments.  This should only
			contain the version number.
		"""
		version_format = (
			"Version should be in a form kind of like '1.2.3[pre4]'")
		if len(args) != 1:
			sys.exit("Must specify exactly one argument to change-versions")
		version = args[0]
		try:
			major, minor, micro_and_pre = version.split(".")
		except ValueError:
			raise SystemExit(version_format)
		if "pre" in micro_and_pre:
			micro, pre = micro_and_pre.split("pre")
		else:
			micro = micro_and_pre
			pre = None
		try:
			major = int(major)
			minor = int(minor)
			micro = int(micro)
			if pre is not None:
				pre = int(pre)
		except ValueError:
			raise SystemExit(version_format)
		version_template = Version("Whatever",
								   major, minor, micro, prerelease=pre)
		self.changeAllProjectVersions(FilePath("."), version_template)
Example #8
0
def buildAllTarballs(checkout, destination):
    """
	Build complete tarballs (including documentation) for Twisted and all
	subprojects.

	This should be called after the version numbers have been updated and
	NEWS files created.

	@type checkout: L{FilePath}
	@param checkout: The SVN working copy from which a pristine source tree
		will be exported.
	@type destination: L{FilePath}
	@param destination: The directory in which tarballs will be placed.

	@raise UncleanWorkingDirectory: if there are modifications to the
		working directory of C{checkout}.
	@raise NotWorkingDirectory: if the checkout path is not an SVN checkout.
	"""
    if not checkout.child(".svn").exists():
        raise NotWorkingDirectory("%s does not appear to be an SVN working directory." % (checkout.path,))
    if runCommand(["svn", "st", checkout.path]).strip():
        raise UncleanWorkingDirectory("There are local modifications to the SVN checkout in %s." % (checkout.path,))

    workPath = FilePath(mkdtemp())
    export = workPath.child("export")
    runCommand(["svn", "export", checkout.path, export.path])
    twistedPath = export.child("twisted")
    version = Project(twistedPath).getVersion()
    versionString = version.base()

    apiBaseURL = "http://twistedmatrix.com/documents/%s/api/%%s.html" % (versionString)
    if not destination.exists():
        destination.createDirectory()
    db = DistributionBuilder(export, destination, apiBaseURL=apiBaseURL)

    db.buildCore(versionString)
    for subproject in twisted_subprojects:
        if subproject not in db.blacklist and twistedPath.child(subproject).exists():
            db.buildSubProject(subproject, versionString)

    db.buildTwisted(versionString)
    workPath.remove()
Example #9
0
	def main(self, args):
		"""
		Build all news files.

		@param args: The command line arguments to process.  This must contain
			one string, the path to the base of the Twisted checkout for which
			to build the news.
		@type args: C{list} of C{str}
		"""
		if len(args) != 1:
			sys.exit("Must specify one argument: the path to the Twisted checkout")
		self.buildAll(FilePath(args[0]))
Example #10
0
    def buildPDF(self, bookPath, inputDirectory, outputPath):
        """
		Build a PDF from the given a LaTeX book document.

		@type bookPath: L{FilePath}
		@param bookPath: The location of a LaTeX document defining a book.

		@type inputDirectory: L{FilePath}
		@param inputDirectory: The directory which the inputs of the book are
			relative to.

		@type outputPath: L{FilePath}
		@param outputPath: The location to which to write the resulting book.
		"""
        if not bookPath.basename().endswith(".tex"):
            raise ValueError("Book filename must end with .tex")

        workPath = FilePath(mkdtemp())
        try:
            startDir = os.getcwd()
            try:
                os.chdir(inputDirectory.path)

                texToDVI = ["latex", "-interaction=nonstopmode", "-output-directory=" + workPath.path, bookPath.path]

                # What I tell you three times is true!
                # The first two invocations of latex on the book file allows it
                # correctly create page numbers for in-text references.  Why this is
                # the case, I could not tell you. -exarkun
                for i in range(3):
                    self.run(texToDVI)

                bookBaseWithoutExtension = bookPath.basename()[:-4]
                dviPath = workPath.child(bookBaseWithoutExtension + ".dvi")
                psPath = workPath.child(bookBaseWithoutExtension + ".ps")
                pdfPath = workPath.child(bookBaseWithoutExtension + ".pdf")
                self.run(["dvips", "-o", psPath.path, "-t", "letter", "-Ppdf", dviPath.path])
                self.run(["ps2pdf13", psPath.path, pdfPath.path])
                pdfPath.moveTo(outputPath)
                workPath.remove()
            finally:
                os.chdir(startDir)
        except:
            workPath.moveTo(bookPath.parent().child(workPath.basename()))
            raise
Example #11
0
	def mapPath(self, fsPathString):
		"""
		Map the given FS path to a ZipPath, by looking at the ZipImporter's
		"archive" attribute and using it as our ZipArchive root, then walking
		down into the archive from there.

		@return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
		"""
		za = ZipArchive(self.importer.archive)
		myPath = FilePath(self.importer.archive)
		itsPath = FilePath(fsPathString)
		if myPath == itsPath:
			return za
		# This is NOT a general-purpose rule for sys.path or __file__:
		# zipimport specifically uses regular OS path syntax in its pathnames,
		# even though zip files specify that slashes are always the separator,
		# regardless of platform.
		segs = itsPath.segmentsFrom(myPath)
		zp = za
		for seg in segs:
			zp = zp.child(seg)
		return zp
Example #12
0
    def mapPath(self, fsPathString):
        """
		Map the given FS path to a ZipPath, by looking at the ZipImporter's
		"archive" attribute and using it as our ZipArchive root, then walking
		down into the archive from there.

		@return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
		"""
        za = ZipArchive(self.importer.archive)
        myPath = FilePath(self.importer.archive)
        itsPath = FilePath(fsPathString)
        if myPath == itsPath:
            return za
        # This is NOT a general-purpose rule for sys.path or __file__:
        # zipimport specifically uses regular OS path syntax in its pathnames,
        # even though zip files specify that slashes are always the separator,
        # regardless of platform.
        segs = itsPath.segmentsFrom(myPath)
        zp = za
        for seg in segs:
            zp = zp.child(seg)
        return zp
Example #13
0
    def getStatusChangeTime(self):
        """
		Return the archive file's status change time.
		"""
        return FilePath(self.zipfile.filename).getStatusChangeTime()
Example #14
0
    def getModificationTime(self):
        """
		Return the archive file's modification time.
		"""
        return FilePath(self.zipfile.filename).getModificationTime()
Example #15
0
    def getAccessTime(self):
        """
		Return the archive file's last access time.
		"""
        return FilePath(self.zipfile.filename).getAccessTime()
Example #16
0
    def exists(self):
        """
		Returns true if the underlying archive exists.
		"""
        return FilePath(self.zipfile.filename).exists()
Example #17
0
 def mapPath(self, fsPathString):
     return FilePath(fsPathString)