Ejemplo n.º 1
0
	def config(self, conf=None, *a, **k):
		"""Return a config dict based on the common pyro(x) rules."""
		try:
			return self.__config
		except:
			if not conf:
				conf = {}
			elif isinstance(conf, basestring):
				conf = base.config(conf)
			else:
				conf = dict(conf)
			
			# kwargs rule
			conf.update(k)
			
			# defaults
			conf.setdefault('module', 'sqlite3')
			
			# Arguments required to open the database; As with kwargs, this 
			# also overrides any arguments specified in conf.
			conf['args'] = a if a else conf.get('args', [])
			
			# path, for file-based databases
			path = conf.get('path')
			if path:
				conf['path'] = base.Path.expand(path)
				conf['args'].insert(0, path)
			
			# module
			m = conf.get('module')
			try:
				conf['module'] = __import__(m)
				conf['modname'] = m
			except Exception as ei:
				try:
					conf['module'] = m
					conf['modname'] = m.__name__
				except Exception as em:
					exdesc = {
						'err-import' : str(ei),
						'err-module' : str(em)
					}
					exdesc['tracebk'] = base.tracebk()
					raise Exception('db-init', exdesc)
			
			# sql
			conf['sql'] = conf.get('sql', {})
			if isinstance(conf['sql'], basestring):
				conf['sql'] = base.config(conf['sql'])
			if not isinstance(conf['sql'], dict):
				raise TypeError('db-config-sql')
				
			# init-check
			conf['autoinit'] = conf.get('autoinit')
			
			self.__config = conf
			return conf
Ejemplo n.º 2
0
	def config(self, *args, **kwargs):
		"""
		Return the configuration dict for this object. First call fully
		instantiates and stores this object's configuration. Subsequent 
		calls return the stored config.
		"""
		try:
			return self.__conf
		
		except Exception:
			config = args[0] if len(args) else {}
			
			# Store args/kwargs for _decore
			self.__args = args
			self.__kwargs = kwargs
			
			if isinstance(config, basestring):
				path = base.Path.expand(config, checkpath=False)
				if os.path.exists(path):
					config = base.config(path)
			
			if not isinstance(config, dict):
				config = {}
			
			# Kwargs always replace config values.
			config.update(kwargs)
			
			# store config and return it
			self.__conf = config
			return self.__conf
Ejemplo n.º 3
0
    def __init__(self, config):
        setup = base.yml(self.file_setup())
        logerr = setup.val("logerr")
        mail = base.yml(self.file_setup()).val("mail")
        cfg = base.config(config)
        bin = base.binary(cfg)
        log = "{}/log".format(bin.path())

        if (not mail):
            return

        if (not bin.exist()):
            return

        if (not os.path.exists(log)):
            return

        if (logerr):
            self.run("{}/script/logerr.sh {} | mail -s \"Linux-CI error: {}: {}\" {}".
                     format(self.dir_top(), log, os.uname()[1], config, mail))
        else:
            self.run("mail -s \"Linux-CI: {}: {}\" {} < {}".
                     format(os.uname()[1], config, mail, log))
Ejemplo n.º 4
0
                      '--yaml',
                      dest='yaml',
                      action='store_true',
                      default=False,
                      help='create makefile via yaml')
    parser.add_option('-c',
                      '--config',
                      dest='config',
                      action='store_true',
                      default=False,
                      help='create makefile via config')
    parser.add_option('-p',
                      '--push',
                      dest='push',
                      action='store_true',
                      default=False,
                      help='git push makefile')

    option, args = parser.parse_args(sys.argv[1:])

    mk = makefile()

    if (option.yaml):
        mk.create_via_yaml(args[0])
    elif (option.config):
        mk.create_via_config(base.config(args[0]))
    elif (option.push):
        mk.create_git_push(args)
    else:
        base.base().die("unknown command")