Example #1
0
def getRasterFiles(path, recursive=False):
  rasters = []
  if not QFileInfo(path).exists():
    return rasters

  # TODO remove *.aux.xml
  _filter = getRasterExtensions()
  workDir = QDir( path )
  workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
  workDir.setNameFilters( _filter )
  files = workDir.entryList()
  for f in files:
    rasters.append( path + "/" + f )

  if recursive:
    for myRoot, myDirs, myFiles in os.walk( unicode(path) ):
      for dir in myDirs:
        workDir = QDir( myRoot + "/" + dir )
        workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
        workDir.setNameFilters( _filter )
        workFiles = workDir.entryList()
        for f in workFiles:
          rasters.append( myRoot + "/" + dir + "/" + f )

  return rasters
Example #2
0
def defaultOutputFolder():
    folder = os.path.join(os.path.dirname(QgsApplication.qgisUserDbFilePath()),
                          "processing", "outputs")
    if not QDir(folder).exists():
        QDir().mkpath(folder)

    return unicode(QDir.toNativeSeparators(folder))
Example #3
0
    def renamePage(self):
        item = self.currentItem()
        oldAttDir = self.itemToAttachmentDir(item)
        parent = item.parent()
        parentPage = self.itemToPage(parent)
        parentPath = os.path.join(self.notePath, parentPage)
        dialog = LineEditDialog(parentPath, self)
        dialog.setText(item.text(0))
        if dialog.exec_():
            newPageName = dialog.editor.text()
            # if hasattr(item, 'text'):       # if item is not QTreeWidget
            if parentPage != '':
                parentPage = parentPage + '/'
            oldFile = self.itemToFile(item)
            newFile = parentPage + newPageName + self.settings.fileExt
            QDir(self.notePath).rename(oldFile, newFile)
            if item.childCount() != 0:
                oldDir = parentPage + item.text(0)
                newDir = parentPage + newPageName
                QDir(self.notePath).rename(oldDir, newDir)
            item.setText(0, newPageName)
            self.sortItems(0, Qt.AscendingOrder)

            # if attachment folder exists, rename it
            if QDir().exists(oldAttDir):
                newAttDir = self.itemToAttachmentDir(item)
                QDir().rename(oldAttDir, newAttDir)
                self.parent.updateAttachmentView()
Example #4
0
    def initialise(notebookName, notebookPath):
        """ Called by create()
        A notebook directory will be initialised to:
            css/  notebook.conf  notes/
        """

        # QDir().mkpath will create all necessary parent directories
        QDir().mkpath(os.path.join(notebookPath, "notes").replace(os.sep, '/'))
        QDir().mkpath(os.path.join(notebookPath, "css").replace(os.sep, '/'))
        cssFile = os.path.join(notebookPath, "css",
                               "notebook.css").replace(os.sep, '/')
        searchCssFile = os.path.join(notebookPath, "css",
                                     "search-window.css").replace(os.sep, '/')
        cssTemplate = "/usr/share/mikidown/notebook.css"
        searchCssTemplate = "/usr/share/mikidown/search-window.css"
        if not os.path.exists(cssTemplate):
            cssTemplate = os.path.join(os.path.dirname(__file__), "css",
                                       "sphinx.css").replace(os.sep, '/')
        if not os.path.exists(searchCssTemplate):
            searchCssTemplate = os.path.join(os.path.dirname(__file__), "css",
                                             "search-window.css").replace(
                                                 os.sep, '/')
        # If //cssFile// already exists, copy() returns false!
        print(cssTemplate)
        print(searchCssTemplate)
        QFile.copy(cssTemplate, cssFile)
        QFile.copy(searchCssTemplate, searchCssFile)
Example #5
0
    def _prepare_help(self, template_dir):
        """Prepare the help directory.

        :param template_dir: Directory where template is.
        :type template_dir: str
        """
        # Copy over pylintrc
        # noinspection PyCallByClass,PyTypeChecker
        QFile.copy(
            os.path.join(template_dir, 'pylintrc'),
            os.path.join(self.plugin_path, 'pylintrc'))
        # Create sphinx default project for help
        QDir().mkdir(self.plugin_path + '/help')
        QDir().mkdir(self.plugin_path + '/help/build')
        QDir().mkdir(self.plugin_path + '/help/source')
        QDir().mkdir(self.plugin_path + '/help/source/_static')
        QDir().mkdir(self.plugin_path + '/help/source/_templates')
        # copy doc makefiles
        # noinspection PyCallByClass,PyTypeChecker
        QFile.copy(
            os.path.join(template_dir, 'help/make.bat'),
            os.path.join(self.plugin_path, 'help/make.bat'))
        # noinspection PyCallByClass,PyTypeChecker
        QFile.copy(
            os.path.join(template_dir, 'help/Makefile'),
            os.path.join(self.plugin_path, 'help/Makefile'))
Example #6
0
def removeDir(path):
    result = ""
    if not QFile(path).exists():
        result = QCoreApplication.translate(
            "QgsPluginInstaller",
            "Nothing to remove! Plugin directory doesn't exist:") + "\n" + path
    elif QFile(path).remove(
    ):  # if it is only link, just remove it without resolving.
        pass
    else:
        fltr = QDir.Dirs | QDir.Files | QDir.Hidden
        iterator = QDirIterator(path, fltr, QDirIterator.Subdirectories)
        while iterator.hasNext():
            item = iterator.next()
            if QFile(item).remove():
                pass
        fltr = QDir.Dirs | QDir.Hidden
        iterator = QDirIterator(path, fltr, QDirIterator.Subdirectories)
        while iterator.hasNext():
            item = iterator.next()
            if QDir().rmpath(item):
                pass
    if QFile(path).exists():
        result = QCoreApplication.translate(
            "QgsPluginInstaller", "Failed to remove the directory:"
        ) + "\n" + path + "\n" + QCoreApplication.translate(
            "QgsPluginInstaller", "Check permissions or remove it manually")
    # restore plugin directory if removed by QDir().rmpath()
    pluginDir = qgis.utils.home_plugin_path
    if not QDir(pluginDir).exists():
        QDir().mkpath(pluginDir)
    return result
Example #7
0
 def create_fb(self):
     """ Create a new empty fieldbook from template and add to layer list. Layer/file name changed to start with 'fb\_' if neccessary.
     """
     ofname = QFileDialog.getSaveFileName(
         self.iface.mainWindow(),
         tr('New fieldbook'),
         filter=tr('Fieldbook file (*.dbf)'))
     if not ofname:
         return
     if QRegExp('fb_').indexIn(QFileInfo(ofname).baseName()):
         ofname = QDir.cleanPath(
             QFileInfo(ofname).absolutePath() + QDir().separator() + 'fb_' +
             QFileInfo(ofname).fileName())
     ofbase = QDir.cleanPath(
         QFileInfo(ofname).absolutePath() + QDir().separator() +
         QFileInfo(ofname).baseName())
     tempbase = QDir.cleanPath(self.plugin_dir + QDir().separator() +
                               'template' + QDir().separator() +
                               'fb_template')
     for ext in ['.dbf']:
         QFile(tempbase + ext).copy(ofbase + ext)
     fb = QgsVectorLayer(ofbase + '.dbf',
                         QFileInfo(ofbase).baseName(), "ogr")
     if fb.isValid():
         QgsMapLayerRegistry.instance().addMapLayer(fb)
Example #8
0
def userFolder():
    userDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() \
        + '/processing'
    if not QDir(userDir).exists():
        QDir().mkpath(userDir)

    return unicode(QDir.toNativeSeparators(userDir))
Example #9
0
def tempFolder():
    tempDir = os.path.join(unicode(QDir.tempPath()),
                           'processing' + _tempFolderSuffix)
    if not QDir(tempDir).exists():
        QDir().mkpath(tempDir)

    return unicode(os.path.abspath(tempDir))
Example #10
0
    def uploadDocument(self, entity_source, doc_type, fileinfo):
        """
        Upload document in central repository
        """
        self._entity_source = entity_source
        self._doc_type = doc_type
        self.fileID = self.generateFileID()
        self.sourcePath = fileinfo.filePath()
        profile_name = self.curr_profile.name
        root_dir = QDir(self.networkPath)
        doc_dir = QDir('{}/{}/{}/{}'.format(
            self.networkPath,
            unicode(profile_name).lower(), self._entity_source,
            unicode(self._doc_type).lower().replace(' ', '_')))
        doc_path_str = u'{}/{}/{}/{}'.format(
            self.networkPath, profile_name.lower(), self._entity_source,
            self._doc_type.lower().replace(' ', '_')).lower()

        if not doc_dir.exists():
            res = root_dir.mkpath(doc_path_str)
            if res:
                root_doc_type_path = doc_path_str

            else:
                root_doc_type_path = self.networkPath

        else:
            root_doc_type_path = doc_path_str

        self.destinationPath = '{}/{}.{}'.format(root_doc_type_path,
                                                 self.fileID,
                                                 fileinfo.completeSuffix())

        srcFile = open(self.sourcePath, 'rb')
        destinationFile = open(self.destinationPath, 'wb')

        #srcLen = self.sourceFile.bytesAvailable()
        totalRead = 0
        while True:
            inbytes = srcFile.read(4096)
            if not inbytes:
                break
            destinationFile.write(inbytes)
            totalRead += len(inbytes)
            #Raise signal on each block written
            self.emit(SIGNAL("blockWritten(int)"), totalRead)

        self.emit(SIGNAL("completed(QString)"), self.fileID)

        srcFile.close()
        destinationFile.close()

        return self.fileID
Example #11
0
 def clearTempFiles(self):
     """
     Clear the directories created for each recording added to the queue
     and the files they contain.
     """
     settingsQDir = QDir(self.settingsDir)
     settingsQDir.setFilter(QDir.Dirs | QDir.NoDotAndDotDot)
     for dir in settingsQDir.entryList():
         tempQDir = QDir(self.settingsDir + '/' + dir)
         tempQDir.setFilter(QDir.Files)
         for tempFile in tempQDir.entryList():
             tempQDir.remove(tempFile)
         settingsQDir.rmdir(self.settingsDir + '/' + dir)
Example #12
0
 def CheckInputValues(self):
     if (self.textNameProject.Value == None or self.textNameProject.Value == ""):
         raise ("Please input project name!")
     if (self.textPathProject.Value == None or self.textPathProject.Value == ""):
         raise ("Please input project path!")
     d = QDir(self.textPathProject.Value)
     if (not d.exists()):
         if (QMessageBox.question(self, "Question", "Procedure path dose not exist! Do you create the directory?", QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes):
             d = QDir(self.textPathProject.Value)
             d.mkpath(self.textPathProject.Value)
         else:
             return False
     return True
Example #13
0
    def validate(self):
        """
        :return: Return True if the source document directory exists,
        otherwise False.
        :rtype: bool
        """
        source_doc_path = self.txtRootFolder.text()

        #Clear previous notifications
        self._notif_bar.clear()

        if not source_doc_path:
            msg = self.tr('Please set the root directory of source documents.')
            self._notif_bar.insertErrorNotification(msg)

            return False

        dir = QDir()

        if not dir.exists(source_doc_path):
            msg = self.tr(
                u"'{0}' directory does not exist.".format(source_doc_path))
            self._notif_bar.insertErrorNotification(msg)

            return False

        return True
 def _get_bpej_code_prices(self):
     """Returns BPEJ code prices.
     
     Returns:
         dict: A dictionary with BPEJ codes as keys (int)
             and prices as values (float).
     
     """
     
     formatTimeStr = '%d.%m.%Y'
     
     bpejDir = QDir(self.pluginDir.path() + u'/data/bpej')
     
     bpejBaseName = u'SC_BPEJ'
     
     bpejZipFileName = bpejBaseName + u'.zip'
     
     bpejZipFilePath = bpejDir.filePath(bpejZipFileName)
     
     bpejCsvFileName = bpejBaseName + u'.csv'
     
     bpejCsvFilePath = bpejDir.filePath(bpejCsvFileName)
     
     upToDate = self._check_bpej_csv(bpejCsvFilePath, formatTimeStr)
     
     if not upToDate:
         testInternetUrl, bpejZipUrl = self._get_url()
         
         self._download_bpej_csv(
             testInternetUrl, bpejZipUrl, bpejZipFilePath, bpejCsvFileName)
     
     bpejCodePrices = self._read_bpej_csv(bpejCsvFilePath, formatTimeStr)
     
     return bpejCodePrices
Example #15
0
    def __init__(self, file, recurse = True, recursion_counter = None, namingregex = None):
        super(FileSystemItem, self).__init__()

        # Raise exception if root path has too many child elements
        if recursion_counter:
            recursion_counter.increment()

        if isinstance(file, QFileInfo):
            self.fileinfo = file
        else:
            self.fileinfo = QFileInfo(file)
        self.fullpath = self.fileinfo.absoluteFilePath()
        self.basename = self.fileinfo.completeBaseName()
        self.displayname = self.fileinfo.fileName() if self.fileinfo.isDir() else self.fileinfo.completeBaseName()
        if namingregex:
            self.displayname = namingregex.match(self.displayname).group(1)
        self.icon = FileSystemItem.iconProvider.icon(self.fileinfo)
        self.isdir = self.fileinfo.isDir()
        self.children = [] if self.isdir else None
        if self.isdir and recurse:
            qdir = QDir(self.fullpath)
            for finfo in qdir.entryInfoList(
                    FileSystemItem.fileExtensions , QDir.Files | QDir.AllDirs | QDir.NoDotAndDotDot,QDir.Name):
                self.children.append(FileSystemItem(finfo, recurse, recursion_counter, namingregex))
        else:
            # file
            # Populate this if and when needed
            self.searchablecontent = None
Example #16
0
 def setUp(self):
     safe_dir_path = os.path.dirname(safe.__file__)
     self.args = CommandLineArguments({
         '--download':
         False,
         '--hazard':
         os.path.join(safe_dir_path, 'test', 'data', 'gisv4', 'hazard',
                      'tsunami_vector.geojson'),
         '--exposure':
         os.path.join(safe_dir_path, 'test', 'data', 'gisv4', 'exposure',
                      'raster', 'population.asc'),
         '--aggregation':
         None,
         '--extent':
         '106,7999364:-6,2085970:106,8525945:-6,1676174',
         '--output-dir':
         'test_cli',
         '--version':
         False,
         'LAYER_NAME': []
     })
     # Let's assume that for this test, the output dir is:
     self.args.output_dir = os.path.join(
         QDir(mkdtemp()).absolutePath(), self.args.output_dir)
     os.makedirs(self.args.output_dir)
Example #17
0
    def initTemplateList(self):
        cbox = self.ui.comboBox_Template
        cbox.clear()
        templateDir = QDir(tools.templateDir())
        for i, entry in enumerate(templateDir.entryList(["*.html", "*.htm"])):
            cbox.addItem(entry)

            config = tools.getTemplateConfig(entry)
            # get template type
            templateType = config.get("type", "plain")
            cbox.setItemData(i, templateType, Qt.UserRole)

            # set tool tip text
            desc = config.get("description", "")
            if desc:
                cbox.setItemData(i, desc, Qt.ToolTipRole)

        # select the template of the settings
        templatePath = self._settings.get("Template")

        # if no template setting, select the last used template
        if not templatePath:
            templatePath = QSettings().value("/Qgis2threejs/lastTemplate",
                                             def_vals.template,
                                             type=unicode)

        if templatePath:
            index = cbox.findText(templatePath)
            if index != -1:
                cbox.setCurrentIndex(index)
            return index
        return -1
Example #18
0
    def setupLanguageMenu(self):
        self.languages = QDir(":/languages").entryList()

        if self.current_language is None:
            self.current_language = QLocale.system().name(
            )  # Retrieve Current Locale from the operating system.
            log.debug("Detected user's locale as %s" % self.current_language)

        for language in self.languages:
            translator = QTranslator(
            )  # Create a translator to translate Language Display Text.
            translator.load(":/languages/%s" % language)
            language_display_text = translator.translate(
                "Translation", "Language Display Text")

            languageAction = QAction(self)
            languageAction.setCheckable(True)
            languageAction.setText(language_display_text)
            languageAction.setData(language)
            self.menuLanguage.addAction(languageAction)
            self.langActionGroup.addAction(languageAction)

            if self.current_language == str(language).strip("tr_").rstrip(
                    ".qm"):
                languageAction.setChecked(True)
Example #19
0
def documentTemplates():
    """
    Return a dictionary of document names and their corresponding absolute file paths.
    """
    from stdm.settings.registryconfig import RegistryConfig

    docTemplates = OrderedDict()

    regConfig = RegistryConfig()
    keyName = "ComposerTemplates"

    pathConfig = regConfig.read([keyName])

    if len(pathConfig) > 0:
        templateDir = pathConfig[keyName]

        pathDir = QDir(templateDir)
        pathDir.setNameFilters(["*.sdt"])
        docFileInfos = pathDir.entryInfoList(QDir.Files, QDir.Name)

        for df in docFileInfos:

            docTemplates[df.completeBaseName()] = df.absoluteFilePath()

    return docTemplates
Example #20
0
	def get_sign_path(self):
		sign_path = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '.',"sign files (*.sign)")
		if sign_path:
			cur_path = QDir('.')
			sign_path = cur_path.relativeFilePath(sign_path)
			sign_path = unicode(sign_path,'utf-8')
			self.ui.Signature.setText(sign_path)
Example #21
0
def main():
    pyqtRemoveInputHook()
    QDir(QDir.homePath()).mkdir(".ricodebug")

    app = QApplication(sys.argv)
    app.setApplicationName("ricodebug")

    Icons()

    # We use all kinds of loggers here:
    # * a CriticalLogHandler that will abort the program whenever a critical error is received
    # * a FileHandler writing to a log in the home directory (all messages, for debugging)
    # * a LogViewHandler to have the log available in the GUI
    # * a ErrorLabelHandler that visually notifies the user of an error or a warning
    logger = logging.getLogger()
    formatter = logging.Formatter('[%(levelname)-8s] : %(filename)15s:%(lineno)4d/%(funcName)-20s : %(message)s')

    filehandler = logging.FileHandler(filename='%s/.ricodebug/ricodebug.log' % str(QDir.homePath()))
    filehandler.setFormatter(formatter)
    logger.addHandler(filehandler)
    logger.setLevel(logging.DEBUG)

    logger.addHandler(criticalloghandler.CriticalLogHandler())

    window = MainWindow()

    logger.addHandler(window.logviewhandler)
    logger.addHandler(window.notificationFrameHandler)

    if (len(sys.argv) > 1):
        window.debugController.openExecutable(sys.argv[1])

    window.show()
    logging.shutdown()
    sys.exit(app.exec_())
Example #22
0
	def get_pub_path(self):
		encpubkey_path = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '.',"pub files (*.pub);;key files (*.key)")
		if encpubkey_path:
			cur_path = QDir('.')
			encpubkey_path = cur_path.relativeFilePath(encpubkey_path)
			encpubkey_path = unicode(encpubkey_path,'utf-8')
			self.ui.EncPubKey.setText(encpubkey_path)
Example #23
0
	def get_pri_path(self):
		signprikey_path = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '.',"pub files (*.pub);;key files (*.key)")
		if signprikey_path:
			cur_path = QDir('.')
			signprikey_path = cur_path.relativeFilePath(signprikey_path)
			signprikey_path = unicode(signprikey_path,'utf-8')
			self.ui.SignPriKey.setText(signprikey_path)
    def reloadPlugins(self):
        self.modules = []
        self.plugins = []

        if self.allPlugins:
            plugin_dir = QDir(
                os.path.join(os.path.dirname(QFile.decodeName(__file__)),
                             "plugins"))
            plugins = plugin_dir.entryList(QDir.Dirs | QDir.NoSymLinks
                                           | QDir.NoDotAndDotDot)
        else:
            p = QSettings().value("/PhyloGeoRec/plugins", "", type=unicode)
            plugins = p.split(",") if p else []

        import importlib
        for name in plugins:
            try:
                modname = "PhyloGeoRec.plugins." + str(name)
                module = reload(
                    sys.modules[modname]
                ) if modname in sys.modules else importlib.import_module(
                    modname)
                self.modules.append(module)
                self.plugins.append(getattr(module, "plugin_class"))
            except ImportError:
                logMessage("Failed to load plugin: " + str(name))
Example #25
0
    def _check_path_exists(self, path, text_box):
        #Validates if the specified folder exists
        dir = QDir()

        if not dir.exists(path):
            msg = self.tr(u"'{0}' directory does not exist.".format(path))
            self.notif_bar.insertErrorNotification(msg)

            #Highlight textbox control
            text_box.setStyleSheet(INVALIDATESTYLESHEET)

            timer = QTimer(self)
            #Sync interval with that of the notification bar
            timer.setInterval(self.notif_bar.interval)
            timer.setSingleShot(True)

            #Remove previous connected slots (if any)
            receivers = timer.receivers(SIGNAL('timeout()'))
            if receivers > 0:
                self._timer.timeout.disconnect()

            timer.start()
            timer.timeout.connect(lambda: self._restore_stylesheet(text_box))

            return False

        return True
Example #26
0
    def __locate_code_in_project(self, queue_folders, nproject):
        file_filter = QDir.Files | QDir.NoDotAndDotDot | QDir.Readable
        dir_filter = QDir.Dirs | QDir.NoDotAndDotDot | QDir.Readable
        while not self._cancel and not queue_folders.empty():
            current_dir = QDir(queue_folders.get())
            #Skip not readable dirs!
            if not current_dir.isReadable():
                continue

            #Collect all sub dirs!
            current_sub_dirs = current_dir.entryInfoList(dir_filter)
            for one_dir in current_sub_dirs:
                queue_folders.put(one_dir.absoluteFilePath())

            #all files in sub_dir first apply the filters
            current_files = current_dir.entryInfoList(
                ['*{0}'.format(x) for x in nproject.extensions], file_filter)
            #process all files in current dir!
            for one_file in current_files:
                try:
                    self._grep_file_locate(one_file.absoluteFilePath(),
                                           one_file.fileName())
                except Exception as reason:
                    logger.error('__locate_code_in_project, error: %r' %
                                 reason)
                    logger.error('__locate_code_in_project fail for file: %r' %
                                 one_file.absoluteFilePath())
Example #27
0
def setup_args(args_dict):
    """Prepares args for test."""
    args = CommandLineArguments(args_dict)
    args.output_dir = os.path.join(
        QDir(mkdtemp()).absolutePath(), args.output_dir)
    os.makedirs(args.output_dir)
    return args
Example #28
0
    def locate_code(self):
        explorerContainer = explorer_container.ExplorerContainer()
        projects_obj = explorerContainer.get_opened_projects()
        projects = [p.path for p in projects_obj]
        if not projects:
            return
        queue = Queue.Queue()
        for project in projects:
            queue.put(project)
        while not self._cancel and not queue.empty():
            current_dir = QDir(queue.get())
            #Skip not readable dirs!
            if not current_dir.isReadable():
                continue

            project_data = project = json_manager.read_ninja_project(
                unicode(current_dir.path()))
            extensions = project_data.get('supported-extensions',
                                          settings.SUPPORTED_EXTENSIONS)

            queue_folders = Queue.Queue()
            queue_folders.put(current_dir)
            self.__locate_code_in_project(queue_folders, extensions)
        self.dirty = True
        self.get_locations()
Example #29
0
 def __init__(self):
     self.__translationPath = QDir(':/i18n')
     self.__availableLanguages = {}
     # Must be put in manually because there exists no translation file
     # UPDATE: well it does now, but we'll keep it this way none the less
     #self.__availableLanguages['en'] = ['English', 'English']
     self.__buildLanguageDictionary()
Example #30
0
 def initTree(self, notePath, parent):
     ''' When there exist foo.md, foo.mkd, foo.markdown,
         only one item will be shown in notesTree.
     '''
     if not QDir(notePath).exists():
         return
     notebookDir = QDir(notePath)
     notesList = notebookDir.entryInfoList(['*.md', '*.mkd', '*.markdown'],
                                           QDir.NoFilter,
                                           QDir.Name | QDir.IgnoreCase)
     nl = [note.completeBaseName() for note in notesList]
     noduplicate = list(set(nl))
     for name in noduplicate:
         item = QTreeWidgetItem(parent, [name])
         path = notePath + '/' + name
         self.initTree(path, item)