示例#1
0
 def build(self):
     """Close the vector map and build vector Topology"""
     self.close()
     libvect.Vect_set_open_level(1)
     if libvect.Vect_open_old2(self.c_mapinfo, self.name, self.mapset, "0") != 1:
         str_err = "Error when trying to open the vector map."
         raise GrassError(str_err)
     # Vect_build returns 1 on success and 0 on error (bool approach)
     if libvect.Vect_build(self.c_mapinfo) != 1:
         str_err = "Error when trying build topology with Vect_build"
         raise GrassError(str_err)
     libvect.Vect_close(self.c_mapinfo)
示例#2
0
 def wrapper(self, *args, **kargs):
     if self.c_mapinfo:
         return method(self, *args, **kargs)
     else:
         raise GrassError(
             _("The self.c_mapinfo pointer must be "
               "correctly initiated"))
示例#3
0
    def rename(self, newname):
        """Method to rename the Vector map

        :param newname: the new name for the Vector map
        :type newname: str
        """
        if self.exist():
            if not self.is_open():
                utils.rename(self.name, newname, "vect")
            else:
                raise GrassError("The map is open, not able to renamed it.")
        self._name = newname
示例#4
0
    def wait(self):
        """Wait for all Module processes that are in the list to finish
        and set the modules stdout and stderr output options
        """
        for proc in self._list:
            if proc:
                stdout, stderr = proc.popen.communicate(input=proc.stdin)
                proc.outputs['stdout'].value = stdout if stdout else ''
                proc.outputs['stderr'].value = stderr if stderr else ''

                if proc.popen.returncode != 0:
                    GrassError(("Error running module %s") % (proc.name))

        self._list = self._num_procs * [None]
        self._proc_count = 0
示例#5
0
    def close(self, build=False):
        """Method to close the Vector

        :param build: True if the vector map should be build before close it
        :type build: bool
        """
        if hasattr(self, "table") and self.table is not None:
            self.table.conn.close()
        if self.is_open():
            if libvect.Vect_close(self.c_mapinfo) != 0:
                str_err = "Error when trying to close the map with Vect_close"
                raise GrassError(str_err)
            if (self.c_mapinfo.contents.mode == libvect.GV_MODE_RW
                    or self.c_mapinfo.contents.mode
                    == libvect.GV_MODE_WRITE) and build:
                self.build()
示例#6
0
    def __init__(self, cmd, *args, **kargs):
        if isinstance(cmd, unicode):
            self.name = str(cmd)
        elif isinstance(cmd, str):
            self.name = cmd
        else:
            raise GrassError(
                "Problem initializing the module {s}".format(s=cmd))
        try:
            # call the command with --interface-description
            get_cmd_xml = Popen([cmd, "--interface-description"], stdout=PIPE)
        except OSError as e:
            print("OSError error({0}): {1}".format(e.errno, e.strerror))
            str_err = "Error running: `%s --interface-description`."
            raise GrassError(str_err % self.name)
        # get the xml of the module
        self.xml = get_cmd_xml.communicate()[0]
        # transform and parse the xml into an Element class:
        # http://docs.python.org/library/xml.etree.elementtree.html
        tree = fromstring(self.xml)

        for e in tree:
            if e.tag not in ("parameter", "flag"):
                self.__setattr__(e.tag, GETFROMTAG[e.tag](e))

        #
        # extract parameters from the xml
        #
        self.params_list = [Parameter(p) for p in tree.findall("parameter")]
        self.inputs = TypeDict(Parameter)
        self.outputs = TypeDict(Parameter)
        self.required = []

        # Insert parameters into input/output and required
        for par in self.params_list:
            if par.input:
                self.inputs[par.name] = par
            else:
                self.outputs[par.name] = par
            if par.required:
                self.required.append(par.name)

        #
        # extract flags from the xml
        #
        flags_list = [Flag(f) for f in tree.findall("flag")]
        self.flags = TypeDict(Flag)
        for flag in flags_list:
            self.flags[flag.name] = flag

        #
        # Add new attributes to the class
        #
        self.run_ = True
        self.finish_ = True
        self.check_ = True
        self.env_ = None
        self.stdin_ = None
        self.stdin = None
        self.stdout_ = None
        self.stderr_ = None
        diz = {
            "name": "stdin",
            "required": False,
            "multiple": False,
            "type": "all",
            "value": None,
        }
        self.inputs["stdin"] = Parameter(diz=diz)
        diz["name"] = "stdout"
        self.outputs["stdout"] = Parameter(diz=diz)
        diz["name"] = "stderr"
        self.outputs["stderr"] = Parameter(diz=diz)
        self._popen = None
        self.time = None
        self.start_time = None  # This variable will be set in the run() function
        # This variable is set True if wait() was successfully called
        self._finished = False
        self.returncode = None

        if args or kargs:
            self.__call__(*args, **kargs)
        self.__call__.__func__.__doc__ = self.__doc__
示例#7
0
 def wrapper(self, *args, **kargs):
     if self.mapset == libgis.G_mapset().decode():
         return method(self, *args, **kargs)
     else:
         raise GrassError(_("Map <{}> not found in current mapset").format(
             self.name))