Exemplo n.º 1
0
def getPixmap(name):
    """
        Returns a QPixmap for the provided 'name', which used to be
        the short form of a filename (without path and file extension).
    """
    Any.requireIsTextNonEmpty(name)

    global _pixmapCache
    global _pixmapDir

    try:
        # lookup cache
        return _pixmapCache[name]

    except KeyError:

        if _pixmapDir is None:
            scriptDir = os.path.dirname(sys.argv[0])
            topLevelDir = ProjectProperties.detectTopLevelDir(scriptDir)

            _pixmapDir = os.path.join(topLevelDir, 'share/pixmaps')
            Any.requireIsDir(_pixmapDir)

        filePath = os.path.join(_pixmapDir, name + '.png')
        Any.requireIsFile(filePath)
        logging.debug('using pixmap: %s', filePath)

        # load pixmap and put in cache
        pixmap = QPixmap(filePath)
        _pixmapCache[pixmap] = pixmap

        return pixmap
Exemplo n.º 2
0
        def check( fileName ):
            Any.requireIsFile( fileName )

            content = FastScript.getFileContent( fileName )

            return content.find( old1 ) != -1 or \
                   content.find( old2 ) != -1
def runMakoEngine(srcFile, dstFile, values):
    """
        Runs the templating engine, applying the given values
        onto the template file 'srcFile', writing results into 'dstFile'.
    """
    Any.requireIsFile(srcFile)
    Any.requireIsText(dstFile)
    Any.requireIsDict(values)

    logging.info('processing %s' % dstFile)

    # First determine the directory of the template file, and tell Mako
    # to search there. In a second step tell Mako to search for a template
    # file in this search path.
    #
    # This is the only solution to get Mako's "include" working.

    lookup = TemplateLookup(directories=[os.path.dirname(srcFile)])
    template = lookup.get_template(os.path.basename(srcFile))

    dstContent = template.render(**values)
    Any.requireIsText(dstContent)

    FastScript.mkdir(os.path.dirname(dstFile))  # ensure dst dir. exists
    FastScript.setFileContent(dstFile, dstContent)
    Any.requireIsFile(dstFile)

    # Mako does not set the executable-flag on the generated output file.
    if os.access(srcFile, os.X_OK):  # if executable
        os.chmod(dstFile, os.stat(srcFile)[0])  # copy mode bits
    def copyVerbatim(self, srcFile, dstFile):
        """
            Copies a file, with standardized info log.
        """
        Any.requireIsFile(srcFile)

        FastScript.mkdir(os.path.dirname(dstFile))  # ensure dstDir exists

        logging.info('processing %s' % dstFile)

        # unlike shutil.copyfile() the shutil.copy2() function also copies
        # attributes such as executable flag (e.g. needed for unittest.sh etc.)
        shutil.copy2(srcFile, dstFile)
Exemplo n.º 5
0
def rename(src, dst):
    """
        Renames/moves a files from "src" path to "dst" path.

        In contrast to Python's os.rename() function this checks the
        validity of the "src" filename first, and requires that the "dst"
        file has been successfully written.
    """
    Any.requireIsTextNonEmpty(src)
    Any.requireIsTextNonEmpty(dst)
    Any.requireIsFile(src)

    dstDir = os.path.dirname(dst)
    mkdir(dstDir)

    os.rename(src, dst)
    Any.requireIsFile(dst)
    def test_bootstrapSIT(self):
        basePkgList = SIT.getMinRequirements()
        outputDir = tempfile.mkdtemp(prefix='test-')

        # create test SIT
        copyFilter = CopyTreeFilter.CopyTreeFilter([])  # skip copying binaries
        copyFilter.filterDocu = True
        SIT.bootstrap(outputDir, True, True, copyFilter.callback, False)

        # check if all essential packages are available
        for package in basePkgList:
            Any.requireIsFile(
                os.path.join(outputDir, package, 'packageVar.cmake'))

        # check for Module-Index directory
        Any.requireIsDir(os.path.join(outputDir, 'Modules', 'Index'))

        # clean-up
        FastScript.remove(outputDir)
Exemplo n.º 7
0
def codeCheck():
    """
        Performs a static source code analysis using PyCharm's built-in
        code inspector.

        The default inspection profile of the project is used, which unless
        modified by the developer will be the common HRI-EU profile coming
        from CreatePyCharmProject.py

        If there is no ".idea" directory in the current directory, it will
        be temporarily created and deleted when finished.

        @returns: defects as list of XML strings

        @see: parseCodeCheckResult()

    """
    ProcessEnv.source(ToolBOSSettings.getConfigOption('package_pycharm'))

    output = StringIO()
    FastScript.execProgram('ps aux', stdout=output, stderr=output)

    if output.getvalue().find('pycharm') > 0:
        raise RuntimeError(
            'PyCharm already running, unable to invoke code checker')

    # create project files if not existing
    if os.path.exists('.idea'):
        created = False
    else:
        created = True
        #createUserConfig()
        createProject()

    resultsDir = 'build/PY05'
    FastScript.remove(resultsDir)
    FastScript.mkdir(resultsDir)

    output.truncate(0)

    cmd = 'inspect.sh . HRI-EU %s' % resultsDir

    try:
        logging.info('running analysis...')
        FastScript.execProgram(cmd, stdout=output, stderr=output)

        if Any.getDebugLevel() > 3:
            logging.info('\n' + output.getvalue())

    except subprocess.CalledProcessError:
        if output.getvalue().find('No valid license found') > 0:
            raise RuntimeError('PyCharm: No valid license found')
        else:
            raise RuntimeError(output.getvalue())

    # delete project files if we have created them
    if created:
        FastScript.remove('.idea')

    resultList = []

    for filePath in glob.glob('build/PY05/*.xml'):
        Any.requireIsFile(filePath)
        content = FastScript.getFileContent(filePath)

        resultList.append(content)

    return resultList