Esempio n. 1
0
    def set_config(self, defaults={}):
        """@brief Initialize opts system and basic variables.
        @param defaults Dictionary with default values for options.
        """
        self.opt = Opt(self._config, defaults)

        # Basic options needed
        self.home = self.opt.get('home')
        self.share = self.opt.get('share')
        self.takuan = self.opt.get('takuan')

        # Log main values
        log.info("Home: " + self.home)
        log.info("Share: " + self.share)
        log.info("Takuan: " + self.takuan)
Esempio n. 2
0
class Idg(object):
    """@brief Main application class

    Opens and closes the program.
    Holds the basis of the program as basic paths and options.
    Loads the i18n system.
    Manages proyects (list, importation, exportation).
    """

    ## Default values (useful when config.xml cannot be found)
    _DEFAULTS = { 'home': ['~/.idiginbpel', 'src'],
                'share': ['~/IdiginBPEL/share', 'src'],
                'takuan': ['~/takuan', 'src'],
                'bpelunit': ['~/AeBpelEngine', 'src'],
                'activebpel': ['~/bin/ActiveBPEL.sh', 'src'],
                'svr': ['localhost', 'value'],
                'port': ['7777', 'value']
               }

    ## Reference to the current open proyect.
    proy = None

    def __init__(self, path, config):
        """@brief Initialize idiginBPEL

        Reads config file, list available proyects and initialize options.
        @param path Absolute path to python executable file in the system.
        @param config Absolute path to the main config file.
        """

        self._config = config
    	self.path = path

        # Set up configuration and proyect list.
        self.set_config(self._DEFAULTS)
        self.update_proylist()

    def set_config(self, defaults={}):
        """@brief Initialize opts system and basic variables.
        @param defaults Dictionary with default values for options.
        """
        self.opt = Opt(self._config, defaults)

        # Basic options needed
        self.home = self.opt.get('home')
        self.share = self.opt.get('share')
        self.takuan = self.opt.get('takuan')

        # Log main values
        log.info("Home: " + self.home)
        log.info("Share: " + self.share)
        log.info("Takuan: " + self.takuan)

    def get_proylist(self):
        """@returns Returns the proyect list"""
        return self._proylist

    def update_proylist(self):
        """@brief Update and returns the list of proyects
        @returns The list of proyects
        """
        # List valid proyects in the user home.
        self._proylist = os.listdir(os.path.join(self.opt.get('home'),"proy"))
        self._proylist = [p for p in self._proylist if p[0] != '.']
        self._proylist.sort()
        log.info(_("idg.main.available.proyects.list") + str(self._proylist))

        return self._proylist

    def exportation(self, name, filepath):
        """@brief Make a tar (gz) package with a proyect directory.
        @param name Name of proyect.
        @param filepath Where the tarfile will be saved.
        """
        if name not in self._proylist:
            return False

        if self.proy is not None and self.proy.nombre == name:
            self.proy.guardar()

        # Compress proyect directory
        try:
            tar = tarfile.open(filepath, "w:gz")
            tar.add(path.join(self.opt.get('home'), "proy", name), arcname=name)
            tar.close()
        except tarfile.TarError, e:
            log.error(e)
            return None

        return True