Example #1
0
    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        sdist_.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()

        self.dist_dir = self.__buildConfiguration.distDirectory
Example #2
0
    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        self.generatemanifestfiles = None
        self.excludepythonshell = None
        self.outputformat = None

        self.__buildConfiguration = BuildConfiguration()
        self.destinationPath = os.path.join(
            "./", self.__buildConfiguration.buildDirectory,
            self.__buildConfiguration.fullName + "_" + sys.platform)
        Command.__init__(self, distribution)
    def __init__(self, distribution):
        """ Constructor. """

        self.__buildConfiguration = BuildConfiguration()
        self.verbose = None
        self.projectname = None
        Command.__init__(self, distribution)
Example #4
0
    def _readConfiguration():
        """ Adds DataFinder specific libraries to the Python path. """

        distutilsSourceDirectory = "build_scripts/distutils/src"
        sys.path.append(os.path.join(os.curdir, distutilsSourceDirectory))

        from datafinder_distutils.configuration import BuildConfiguration

        buildConfiguration = BuildConfiguration("setup.cfg")

        pythonPath = os.environ.get("PYTHONPATH")
        if pythonPath is None:
            pythonPath = ""

        # determine environment separator
        separator = os.pathsep

        # adapt PYTHONPATH
        workingDirectory = os.curdir
        sourcePaths = list()
        sourcePaths.append(
            os.path.join(workingDirectory, buildConfiguration.sourceDirectory))
        sourcePaths.append(
            os.path.join(workingDirectory,
                         buildConfiguration.unittestDirectory))

        # set environment variable PYTHONPATH
        # add paths to internal PYTHONPATH
        for path in sourcePaths:
            if not path in sys.path:
                sys.path.append(path)
            pythonPath += os.path.realpath(path) + separator
        os.environ["PYTHONPATH"] = pythonPath
        return buildConfiguration
Example #5
0
    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        self.pylintcommand = None
        self.outputformat = None
        Command.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()
Example #6
0
 def __init__(self, distribution):
     """ Constructor. """
     
     self.verbose = None
     sdist_.__init__(self, distribution)
     self.__buildConfiguration = BuildConfiguration()
     
     self.dist_dir = self.__buildConfiguration.distDirectory
Example #7
0
    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        self.nosecommand = None
        self.outputformat = None
        self.coveragecommand = None
        self.coverageoutputformat = None
        self.__buildConfiguration = BuildConfiguration()
        Command.__init__(self, distribution)
Example #8
0
    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        self.outputdirectory = None

        Command.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()
        self.__sourceDistributionDirectory = os.path.join(
            self.__buildConfiguration.buildDirectory,
            self.__buildConfiguration.fullName + "_" + sys.platform)
Example #9
0
 def __init__(self, distribution):
     """ Constructor. """
     
     self.verbose = None
     self.generatemanifestfiles = None
     self.excludepythonshell = None
     self.outputformat = None
     
     self.__buildConfiguration = BuildConfiguration()
     self.destinationPath = os.path.join("./", 
                                         self.__buildConfiguration.buildDirectory,
                                         self.__buildConfiguration.fullName + "_" + sys.platform)
     Command.__init__(self, distribution)
Example #10
0
 def __init__(self, distribution):
     """ Constructor. """
     
     self.verbose = None
     self.nsiscommand = None
     self.nsismainscript = None
     self.nsisdefinitions = None
     self.starturl = None
     self.usericonname = None
     self.adminiconname = None
     
     Command.__init__(self, distribution)
     self.__buildConfiguration = BuildConfiguration()
     self.__userClientExecutable = os.path.basename(self.__buildConfiguration.userClientStartScript)
     self.__userClientExecutable = self.__userClientExecutable.replace(".py", ".exe")
     self.__adminClientExecutable = os.path.basename(self.__buildConfiguration.adminClientStartScript)
     self.__adminClientExecutable = self.__adminClientExecutable.replace(".py", ".exe")
     self.__sourceDistributionDirectory = os.path.join(self.__buildConfiguration.buildDirectory,
                                                       self.__buildConfiguration.fullName + "_" + sys.platform)
Example #11
0
class bdist(Command):
    """ Creates a binary distribution containing all required C and Python extensions. """
    
    description = "Creates a platform-specific DataFinder distribution including all " + \
                  "required Python and C dependencies." 
    user_options = [("excludepythonshell", 
                     None, 
                     "Flag indicating the exclusion of the separate Python shell."),
                     ("outputformat=", 
                     None, 
                     "Format of the package format (nsis: NSIS installer (win32 only), " \
                     + "tar compressed tar archive). Default: No archive is created.")]
    sub_commands = [("gen", None), ("doc", None)]

    
    def __init__(self, distribution):
        """ Constructor. """
        
        self.verbose = None
        self.generatemanifestfiles = None
        self.excludepythonshell = None
        self.outputformat = None
        
        self.__buildConfiguration = BuildConfiguration()
        self.destinationPath = os.path.join("./", 
                                            self.__buildConfiguration.buildDirectory,
                                            self.__buildConfiguration.fullName + "_" + sys.platform)
        Command.__init__(self, distribution)

    def initialize_options(self):
        """ Definition of command options. """
        
        self.excludepythonshell = False
        self.outputformat = None
        self.verbose = False
        
    def finalize_options(self):
        """ Set final values of options. """
        
        self.verbose = self.distribution.verbose
        self.excludepythonshell = bool(int(self.excludepythonshell))
        
    def run(self):
        """ Perform command actions. """

        # Preparation...        
        self._prepare()
        
        # Run sub commands
        for commandName in self.get_sub_commands():
            self.run_command(commandName)
        
        # Create the binary distribution
        from distutils import dist
        distutilDistributionClass = dist.Distribution # save reference to distutils Distribution class because it is overwritten by bbfreeze
        startScripts = [(scriptName, False) for scriptName in self.__buildConfiguration.getScripts()]
        self._createBinaryDistribution(startScripts)
        setattr(dist, "Distribution", distutilDistributionClass) # correct reference again so later build targets work properly
        
        if self.outputformat == "tar":
            self.run_command("_bdist_tar")
        elif self.outputformat == "nsis":
            self.run_command("_bdist_nsis")
        
    def _prepare(self):
        """ Prepares the source distribution creation. """
        
        epydocOptions = self.distribution.get_option_dict("doc")
        epydocOptions["destdir"] = ("", _DOCUMENTATION_DIRECTORY)
        modules = "src/datafinder/script_api"
        modules += ";src/datafinder/gui/user/script_api.py"
        epydocOptions["modules"] = ("", modules)

        setVersion(self.__buildConfiguration.fullName)

    def _createBinaryDistribution(self, startScripts):
        """ 
        Creates a binary DataFinder distribution for Linux/Windows platforms
        including the Python interpreter.
        
        @param startScripts: Contains a list of start scripts for which executables are generated. The scripts
                             are described by tuples of script path and a boolean indicating whether 
                             on the Windows platform a console window is visible or not.
        @type startScripts: C{list} of C{tuple} (C{unicode}/C{string}, C{bool})
        """
        
        forcedIncludes = _forcedIncludes[:]
        forcedIncludes.extend(_qtSpecificForcedIncludes)
        if sys.platform == "win32":
            forcedIncludes.extend(_win32ForcedIncludes)
        
        freezer = Freezer(self.destinationPath, includes=forcedIncludes)
        freezer.include_py = not self.excludepythonshell
        for scriptPath, guiOnly in startScripts:
            freezer.addScript(scriptPath, gui_only=guiOnly)
        
        # create distribution
        freezer()
        
        # copy readme, license, changes files
        shutil.copy(self.__buildConfiguration.readmeFile, self.destinationPath)
        shutil.copy(self.__buildConfiguration.licenseFile, self.destinationPath)
        shutil.copy(self.__buildConfiguration.changesFile, self.destinationPath)
        
        # copy image, example script files
        destinationImagePath = os.path.join(self.destinationPath, self.__buildConfiguration.imageDirectory)
        os.makedirs(destinationImagePath)
        baseImageDir = self.__buildConfiguration.imageDirectory
        for imageName in os.listdir(baseImageDir):
            if imageName.endswith(".ico"):
                shutil.copy(os.path.join(baseImageDir, imageName), destinationImagePath)
        
        scriptsExampleDir = self.__buildConfiguration.scriptExamplesDirectory
        shutil.copytree(scriptsExampleDir, os.path.join(self.destinationPath, scriptsExampleDir))
        docDir = "doc"
        shutil.copytree(docDir, os.path.join(self.destinationPath, docDir))
        shutil.rmtree(docDir)

        # create manifest files
        if sys.platform == "win32":
            scriptNames = [startScript[0] for startScript in startScripts]
            if not self.excludepythonshell:
                scriptNames.append("py.py")
            
            for scriptName in scriptNames:
                fileExtension = ".exe.manifest"
                content = _MANIFEST_FILE_CONTENT
                    
                fileBaseName = os.path.basename(scriptName).replace(".py", fileExtension)
                filePath = os.path.join(self.destinationPath, fileBaseName)
                fileHandle = open(filePath, "wb")
                fileHandle.write(content)
                fileHandle.close()
Example #12
0
class sdist(sdist_):
    """ Adapted sdist target. """
    
    sub_commands = [("gen", None), ("doc", None)]


    def __init__(self, distribution):
        """ Constructor. """
        
        self.verbose = None
        sdist_.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()
        
        self.dist_dir = self.__buildConfiguration.distDirectory
    
    def run(self):
        """ 
        Sets some new configuration values and runs 
        the default run method of the sdist target.
        """

        # Adjust epydoc parameters, create manifest template, etc.
        self._prepare()
                
        # Run commands
        for commandName in self.get_sub_commands():
            self.run_command(commandName)
        self.distribution.packages = self.__buildConfiguration.getPackages() # Ensure that all packages are in
        self._createManifestTemplate()
        sdist_.run(self)
        
        # Clean up
        shutil.rmtree(_DOCUMENTATION_DIRECTORY)
        
    def _prepare(self):
        """ Prepares the source distribution creation. """
        
        epydocOptions = self.distribution.get_option_dict("doc")
        epydocOptions["destdir"] = ("", _DOCUMENTATION_DIRECTORY)
        modules = "src/datafinder/script_api"
        if not self.__buildConfiguration.excludeClients:
            modules += ";src/datafinder/gui/user/script_api.py"
        epydocOptions["modules"] = ("", modules)

        setVersion(self.__buildConfiguration.fullName)
        self._adjustSetupConfigurationFile()
        
    def _createManifestTemplate(self):
        """ Handles the creation of the manifest template file. """
        
        try:
            manifestFileObject = open("MANIFEST.in", "wb")
            for filePath in self._getAdditionalFiles():
                manifestFileObject.write("include %s\n" % filePath)
            for fileName in os.listdir(_DOCUMENTATION_DIRECTORY):
                manifestFileObject.write("include %s\n" % (os.path.join(_DOCUMENTATION_DIRECTORY, 
                                                                        fileName)))
            manifestFileObject.close()
        except IOError:
            print("Cannot create manifest template file.")
            sys.exit(-1)
            
    def _getAdditionalFiles(self):
        """ Determines all files which should be distributed but not installed. """
        
        additionalFiles = [self.__buildConfiguration.changesFile, 
                           self.__buildConfiguration.licenseFile,
                           os.path.join("script_extensions", "README.txt")]
        topLevelDirectories = [self.__buildConfiguration.unittestDirectory, 
                               self.__buildConfiguration.distutilSourceDirectory, 
                               self.__buildConfiguration.scriptExamplesDirectory]
        for directory in topLevelDirectories:
            for rootPath, dirNames, fileNames in os.walk(directory):
                for fileName in fileNames:
                    if fileName.endswith(".py") and not fileName in _IGNORE_BUILD_TARGETS:
                        additionalFiles.append(os.path.join(rootPath, fileName))
                if self.__buildConfiguration.excludeClients and "gui" in dirNames:
                    dirNames.remove("gui")
        return additionalFiles 

    def _adjustSetupConfigurationFile(self):
        """ Corrects the exclude_clients parameter so 
        everything works on installation as expected. """
        
        configurationFileObject = open(_CONFIGURATION_FILE_NAME, "rb")
        lines = configurationFileObject.readlines()
        configurationFileObject.close()
        for line in lines:
            if _EXCLUDE_CLIENTS_KEYWORD in line:
                index =  lines.index(line)
                lines.remove(line)
                lines.insert(index, _EXCLUDE_CLIENTS_KEYWORD + "=" 
                             + str(int(self.__buildConfiguration.excludeClients)) + "\n")
            elif _REVISION_KEYWORD in line:
                index =  lines.index(line)
                lines.remove(line)
                lines.insert(index, _REVISION_KEYWORD + "=" 
                             + self.__buildConfiguration.revision + "\n")
            elif _IS_RELEASE_KEYWORD in line:
                index =  lines.index(line)
                lines.remove(line)
                lines.insert(index, _IS_RELEASE_KEYWORD + "=" 
                             + str(int(self.__buildConfiguration.isRelease)) + "\n")
        configurationFileObject = open(_CONFIGURATION_FILE_NAME, "wb")
        configurationFileObject.writelines(lines)
        configurationFileObject.close()
Example #13
0
class sdist(sdist_):
    """ Adapted sdist target. """

    sub_commands = [("gen", None), ("doc", None)]

    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        sdist_.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()

        self.dist_dir = self.__buildConfiguration.distDirectory

    def run(self):
        """ 
        Sets some new configuration values and runs 
        the default run method of the sdist target.
        """

        # Adjust epydoc parameters, create manifest template, etc.
        self._prepare()

        # Run commands
        for commandName in self.get_sub_commands():
            self.run_command(commandName)
        self.distribution.packages = self.__buildConfiguration.getPackages(
        )  # Ensure that all packages are in
        self._createManifestTemplate()
        sdist_.run(self)

        # Clean up
        shutil.rmtree(_DOCUMENTATION_DIRECTORY)

    def _prepare(self):
        """ Prepares the source distribution creation. """

        epydocOptions = self.distribution.get_option_dict("doc")
        epydocOptions["destdir"] = ("", _DOCUMENTATION_DIRECTORY)
        modules = "src/datafinder/script_api"
        if not self.__buildConfiguration.excludeClients:
            modules += ";src/datafinder/gui/user/script_api.py"
        epydocOptions["modules"] = ("", modules)

        setVersion(self.__buildConfiguration.fullName)
        self._adjustSetupConfigurationFile()

    def _createManifestTemplate(self):
        """ Handles the creation of the manifest template file. """

        try:
            manifestFileObject = open("MANIFEST.in", "wb")
            for filePath in self._getAdditionalFiles():
                manifestFileObject.write("include %s\n" % filePath)
            for fileName in os.listdir(_DOCUMENTATION_DIRECTORY):
                manifestFileObject.write(
                    "include %s\n" %
                    (os.path.join(_DOCUMENTATION_DIRECTORY, fileName)))
            manifestFileObject.close()
        except IOError:
            print("Cannot create manifest template file.")
            sys.exit(-1)

    def _getAdditionalFiles(self):
        """ Determines all files which should be distributed but not installed. """

        additionalFiles = [
            self.__buildConfiguration.changesFile,
            self.__buildConfiguration.licenseFile,
            os.path.join("script_extensions", "README.txt")
        ]
        topLevelDirectories = [
            self.__buildConfiguration.unittestDirectory,
            self.__buildConfiguration.distutilSourceDirectory,
            self.__buildConfiguration.scriptExamplesDirectory
        ]
        for directory in topLevelDirectories:
            for rootPath, dirNames, fileNames in os.walk(directory):
                for fileName in fileNames:
                    if fileName.endswith(
                            ".py") and not fileName in _IGNORE_BUILD_TARGETS:
                        additionalFiles.append(os.path.join(
                            rootPath, fileName))
                if self.__buildConfiguration.excludeClients and "gui" in dirNames:
                    dirNames.remove("gui")
        return additionalFiles

    def _adjustSetupConfigurationFile(self):
        """ Corrects the exclude_clients parameter so 
        everything works on installation as expected. """

        configurationFileObject = open(_CONFIGURATION_FILE_NAME, "rb")
        lines = configurationFileObject.readlines()
        configurationFileObject.close()
        for line in lines:
            if _EXCLUDE_CLIENTS_KEYWORD in line:
                index = lines.index(line)
                lines.remove(line)
                lines.insert(
                    index, _EXCLUDE_CLIENTS_KEYWORD + "=" +
                    str(int(self.__buildConfiguration.excludeClients)) + "\n")
            elif _REVISION_KEYWORD in line:
                index = lines.index(line)
                lines.remove(line)
                lines.insert(
                    index, _REVISION_KEYWORD + "=" +
                    self.__buildConfiguration.revision + "\n")
            elif _IS_RELEASE_KEYWORD in line:
                index = lines.index(line)
                lines.remove(line)
                lines.insert(
                    index, _IS_RELEASE_KEYWORD + "=" +
                    str(int(self.__buildConfiguration.isRelease)) + "\n")
        configurationFileObject = open(_CONFIGURATION_FILE_NAME, "wb")
        configurationFileObject.writelines(lines)
        configurationFileObject.close()
Example #14
0
    def __init__(self, distribution):
        """ Constructor. """

        Command.__init__(self, distribution)
        self.__buildConfiguration = BuildConfiguration()
Example #15
0
class bdist(Command):
    """ Creates a binary distribution containing all required C and Python extensions. """

    description = "Creates a platform-specific DataFinder distribution including all " + \
                  "required Python and C dependencies."
    user_options = [("excludepythonshell",
                     None,
                     "Flag indicating the exclusion of the separate Python shell."),
                     ("outputformat=",
                     None,
                     "Format of the package format (nsis: NSIS installer (win32 only), " \
                     + "tar compressed tar archive). Default: No archive is created.")]
    sub_commands = [("gen", None), ("doc", None)]

    def __init__(self, distribution):
        """ Constructor. """

        self.verbose = None
        self.generatemanifestfiles = None
        self.excludepythonshell = None
        self.outputformat = None

        self.__buildConfiguration = BuildConfiguration()
        self.destinationPath = os.path.join(
            "./", self.__buildConfiguration.buildDirectory,
            self.__buildConfiguration.fullName + "_" + sys.platform)
        Command.__init__(self, distribution)

    def initialize_options(self):
        """ Definition of command options. """

        self.excludepythonshell = False
        self.outputformat = None
        self.verbose = False

    def finalize_options(self):
        """ Set final values of options. """

        self.verbose = self.distribution.verbose
        self.excludepythonshell = bool(int(self.excludepythonshell))

    def run(self):
        """ Perform command actions. """

        # Preparation...
        self._prepare()

        # Run sub commands
        for commandName in self.get_sub_commands():
            self.run_command(commandName)

        # Create the binary distribution
        from distutils import dist
        distutilDistributionClass = dist.Distribution  # save reference to distutils Distribution class because it is overwritten by bbfreeze
        startScripts = [
            (scriptName, False)
            for scriptName in self.__buildConfiguration.getScripts()
        ]
        self._createBinaryDistribution(startScripts)
        setattr(
            dist, "Distribution", distutilDistributionClass
        )  # correct reference again so later build targets work properly

        if self.outputformat == "tar":
            self.run_command("_bdist_tar")
        elif self.outputformat == "nsis":
            self.run_command("_bdist_nsis")

    def _prepare(self):
        """ Prepares the source distribution creation. """

        epydocOptions = self.distribution.get_option_dict("doc")
        epydocOptions["destdir"] = ("", _DOCUMENTATION_DIRECTORY)
        modules = "src/datafinder/script_api"
        modules += ";src/datafinder/gui/user/script_api.py"
        epydocOptions["modules"] = ("", modules)

        setVersion(self.__buildConfiguration.fullName)

    def _createBinaryDistribution(self, startScripts):
        """ 
        Creates a binary DataFinder distribution for Linux/Windows platforms
        including the Python interpreter.
        
        @param startScripts: Contains a list of start scripts for which executables are generated. The scripts
                             are described by tuples of script path and a boolean indicating whether 
                             on the Windows platform a console window is visible or not.
        @type startScripts: C{list} of C{tuple} (C{unicode}/C{string}, C{bool})
        """

        forcedIncludes = _forcedIncludes[:]
        forcedIncludes.extend(_qtSpecificForcedIncludes)
        if sys.platform == "win32":
            forcedIncludes.extend(_win32ForcedIncludes)

        freezer = Freezer(self.destinationPath, includes=forcedIncludes)
        freezer.include_py = not self.excludepythonshell
        for scriptPath, guiOnly in startScripts:
            freezer.addScript(scriptPath, gui_only=guiOnly)

        # create distribution
        freezer()

        # copy readme, license, changes files
        shutil.copy(self.__buildConfiguration.readmeFile, self.destinationPath)
        shutil.copy(self.__buildConfiguration.licenseFile,
                    self.destinationPath)
        shutil.copy(self.__buildConfiguration.changesFile,
                    self.destinationPath)

        # copy image, example script files
        destinationImagePath = os.path.join(
            self.destinationPath, self.__buildConfiguration.imageDirectory)
        os.makedirs(destinationImagePath)
        baseImageDir = self.__buildConfiguration.imageDirectory
        for imageName in os.listdir(baseImageDir):
            if imageName.endswith(".ico"):
                shutil.copy(os.path.join(baseImageDir, imageName),
                            destinationImagePath)

        scriptsExampleDir = self.__buildConfiguration.scriptExamplesDirectory
        shutil.copytree(scriptsExampleDir,
                        os.path.join(self.destinationPath, scriptsExampleDir))
        docDir = "doc"
        shutil.copytree(docDir, os.path.join(self.destinationPath, docDir))
        shutil.rmtree(docDir)

        # create manifest files
        if sys.platform == "win32":
            scriptNames = [startScript[0] for startScript in startScripts]
            if not self.excludepythonshell:
                scriptNames.append("py.py")

            for scriptName in scriptNames:
                fileExtension = ".exe.manifest"
                content = _MANIFEST_FILE_CONTENT

                fileBaseName = os.path.basename(scriptName).replace(
                    ".py", fileExtension)
                filePath = os.path.join(self.destinationPath, fileBaseName)
                fileHandle = open(filePath, "wb")
                fileHandle.write(content)
                fileHandle.close()