Пример #1
0
    def onAddImportDir( self ):
        " Displays a directory selection dialog "

        dirName = QFileDialog.getExistingDirectory( self,
                    "Select import directory",
                    self.dirEdit.text(),
                    QFileDialog.Options( QFileDialog.ShowDirsOnly ) )

        if not dirName:
            return

        # There are 2 cases: new project or
        # editing the existed project properties
        if self.__project is None:
            # It a new project; the project path could be editedd
            dirToInsert = dirName
        else:
            # This is an existed project; no way the project path is changed
            # Let's decide it a relative path should be used here
            if self.__project.isProjectDir( dirName ):
                dirToInsert = relpath( dirName, self.dirEdit.text() )
            else:
                dirToInsert = dirName

        index = 0
        while index < self.importDirList.count():
            if self.importDirList.item( index ).text() == dirToInsert:
                logging.warning( "The directory '" + dirName +
                                 "' is already in the list of "
                                 "imported directories and is not added." )
                return
            index += 1

        self.importDirList.addItem( dirToInsert )
        self.importDirList.setCurrentRow( self.importDirList.count() - 1 )
        return
    def __viewProperties( self ):
        " Handles the 'view properties' context menu item "
        if self.__projectContextItem is None:
            return
        if not self.__projectContextItem.isValid():
            return

        if self.__projectContextItem.isCurrent():
            # This is the current project - it can be edited
            project = GlobalData().project
            dialog = ProjectPropertiesDialog( project )
            if dialog.exec_() == QDialog.Accepted:
                importDirs = []
                for index in xrange( dialog.importDirList.count() ):
                    importDirs.append( dialog.importDirList.item( index ).text() )

                scriptName = dialog.scriptEdit.text().strip()
                relativePath = relpath( scriptName, project.getProjectDir() )
                if not relativePath.startswith( '..' ):
                    scriptName = relativePath

                project.updateProperties(
                    scriptName, importDirs,
                    dialog.creationDateEdit.text().strip(),
                    dialog.authorEdit.text().strip(),
                    dialog.licenseEdit.text().strip(),
                    dialog.copyrightEdit.text().strip(),
                    dialog.versionEdit.text().strip(),
                    dialog.emailEdit.text().strip(),
                    dialog.descriptionEdit.toPlainText().strip() )
        else:
            # This is not the current project - it can be viewed
            fName = self.__projectContextItem.getFilename()
            dialog = ProjectPropertiesDialog( fName )
            dialog.exec_()
        return
Пример #3
0
    def __viewProperties(self):
        " Handles the 'view properties' context menu item "
        if self.__projectContextItem is None:
            return
        if not self.__projectContextItem.isValid():
            return

        if self.__projectContextItem.isCurrent():
            # This is the current project - it can be edited
            project = GlobalData().project
            dialog = ProjectPropertiesDialog(project, self)
            if dialog.exec_() == QDialog.Accepted:
                importDirs = []
                for index in xrange(dialog.importDirList.count()):
                    importDirs.append(dialog.importDirList.item(index).text())

                scriptName = dialog.scriptEdit.text().strip()
                relativePath = relpath(scriptName, project.getProjectDir())
                if not relativePath.startswith('..'):
                    scriptName = relativePath

                project.updateProperties(
                    scriptName, importDirs,
                    dialog.creationDateEdit.text().strip(),
                    dialog.authorEdit.text().strip(),
                    dialog.licenseEdit.text().strip(),
                    dialog.copyrightEdit.text().strip(),
                    dialog.versionEdit.text().strip(),
                    dialog.emailEdit.text().strip(),
                    dialog.descriptionEdit.toPlainText().strip())
        else:
            # This is not the current project - it can be viewed
            fName = self.__projectContextItem.getFilename()
            dialog = ProjectPropertiesDialog(fName, self)
            dialog.exec_()
        return
Пример #4
0
def getDisassembled( path, name ):
    " Provides disassembler output for thr given name "

    if not os.path.exists( path ):
        raise Exception( "Cannot find file " + path )
    if not os.path.isfile( path ):
        raise Exception( "The path '" + path + "' does not point to a file" )
    if not path.endswith( '.py' ) and not path.endswith( '.py3' ):
        raise Exception( "Path must point to a python file" )

    cmdLine2 = ""
    project = GlobalData().project
    importDirs = GlobalData().getProjectImportDirs()
    if project.isProjectFile:
        # There are at least two options:
        # - to import starting from the project top level dir (project main
        #   script dir)
        # - to import starting from the directory where the script is located
        # Let's try both of them
        if project.scriptName != "" and os.path.exists( project.scriptName ):
            topDir = os.path.dirname( project.scriptName )
        else:
            topDir = os.path.dirname( project.fileName )

        scriptDir = os.path.dirname( path )
        if topDir == scriptDir:
            cmdLine = _getCodeForStandaloneScript( path, name, importDirs )
        else:
            # Calculate the relative path
            # it will be like 'c/d/e/my.py'
            relativePath = relpath( path, topDir )

            # Make sure there are __init__ files in all paths down
            if _checkInitPresence( topDir,
                                   os.path.dirname( relativePath ) ) == False:
                # No init files in the structure, so there is no point to try
                # importing from the project top directory
                cmdLine = _getCodeForStandaloneScript( path,
                                                       name, importDirs )
            else:
                # Need to try both options of importing
                # We may get luck succesfully loading it
                cmdLine = _getCodeForStandaloneScript( path,
                                                       name, importDirs )

                cmdLine2 = _getCodeForNestedScript( topDir,
                                                    relativePath,
                                                    name, importDirs )
    else:
        cmdLine = _getCodeForStandaloneScript( path, name, importDirs )

    # cmdLine is formed in any case
    # cmdLine2 only if certain conditions are met
    try:
        return runWithShell( cmdLine )
    except:
        if cmdLine2 != "":
            try:
                return runWithShell( cmdLine2 )
            except:
                pass
    raise Exception( "Could not get '" + name + "' disassembled" )