Python utils 模块,error() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用utils.error()

项目:SiteFab    作者:ebursztein    | 项目源码 | 文件源码
def display_execution_results(self, results, site):
        """ Display execution summary
        """
        cprint("|-Execution result", "magenta")
        count = 0
        for result in results:
            plugin_name, stats = result
            c = "cyan"
            if count % 2:
                c = "blue"

            name = colored("  |-%15s" % plugin_name, c)
            ok = colored("ok:%s"% stats[site.OK], "green")
            skip = colored("skip:%s" % stats[site.SKIPPED], "yellow")
            err = colored("error:%s" % stats[site.ERROR], "red")
            print "%s\t%s\t%s\t%s" % (name, ok, skip, err)
            count += 1
项目:SiteFab    作者:ebursztein    | 项目源码 | 文件源码
def render_posts(self):
        """Render posts using jinja2 templates."""

        for post in tqdm(self.posts, unit=' pages', miniters=1, desc="Posts"):
            template_name = "%s.html" % post.meta.template
            template = self.jinja2.get_template(template_name)
            html = post.html.decode("utf-8", 'ignore')
            rv = template.render(content=html, meta=post.meta, posts=self.posts, plugin_data=self.plugin_data, config=self.config,
            categories=self.posts_by_category.get_as_dict(), tags=self.posts_by_tag.get_as_dict(), templates=self.posts_by_template.get_as_dict(), 
            microdata=self.posts_by_microdata.get_as_dict())

            # Liniting            
            linter_results = self.linter.lint(post, rv, self)
            # Are we stopping on linting errors?
            if linter_results.has_errors and self.config.linter.stop_on_error:
                print post.filename
                for error in linter_results.info:
                    print "\t-%s:%s" % (error[0], error[1])
                sys.exit(-1)

            path = "%s%s/" % (self.get_output_dir(), post.meta.permanent_url)
            path = path.replace('//', '/')
            files.write_file(path, 'index.html', rv)

    ### Templates functions ###
项目:SiteFab    作者:ebursztein    | 项目源码 | 文件源码
def inject_parser_html_template(self, pluging_name, html_elt, jinja_template):
        """Allows plugins to replace the template of a given HTML element with their own
        Args:
            pluging_name (str): the name of the plugin responsible for the injection. Used for debug
            html_elt (str): the HTML element the template is for 
            jinja_template (str): The jinja_template that will be used to render a given element

        Return:
            bool: True ok, False error

        note: Due to the way plugins works a template can be overwritten many time. It is okay

        """

        if not html_elt or not jinja_template or not pluging_name:
            error("%s: plugin_name or html_elt or template not specified in inject_parser_template", pluging_name)
            return False

        self.config.parser.injected_html_templates[html_elt] = jinja_template
        self.config.parser.injected_html_templates_owner[html_elt] = pluging_name
        return True
项目:GAKeras    作者:PetraVidnerova    | 项目源码 | 文件源码
def evaluate(self, individual):
        #print(" *** evaluate *** ")

        #model = individual.createNetwork()
        #return random.random(), 

        random.seed(42) 
        # perform KFold crossvalidation 
        kf = KFold(n_splits=3)
        scores = []
        for train, test in kf.split(self.X):   # train, test are indicies 
            X_train, X_test = self.X[train], self.X[test]
            y_train, y_test = self.y[train], self.y[test]

            model = individual.createNetwork()
            model.fit(X_train, y_train,
                      batch_size=Config.batch_size, nb_epoch=Config.epochs, verbose=0)

            yy_test = model.predict(X_test)
            scores.append(error(y_test, yy_test))

        fitness = np.mean(scores)

        return fitness,
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def load_apilog(self, log_fname, limit):
        with open(log_fname, 'rb') as f:
            data = f.read().split('\n')[:-1]
        if len(data) %2 !=0:
            data = data[:-1]
        idx = 0
        apilogs = []
        while idx < len(data) and idx < limit*2:
            if data[idx][:2] == 'IN':
                il = utils.evaluate(data[idx][2:])
            else:
                utils.error('load_apilog: parse IN error')

            if data[idx+1][:3] == 'OUT' :
                ol = utils.evaluate(data[idx+1][3:])
            else:
                utils.error('load_apilog: parse OUT error')
            apilog = log.ApiLog(self.apis[il[0]], il, ol)
            apilogs.append(apilog)
            idx+=2
        return apilogs
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def make_cfdic(ori):
    if type(ori) == type({}):
        ret = 'make_CFDic()'
        for key in ori:
            v1 = make_cfdic(key)
            v2 = make_cfdic(ori[key])
            ret = 'set_CFDic(%s,%s,%s)'%(ret, v1, v2)
        return ret
    elif type(ori) == type(''):
        return 'CFSTR(\"%s\")'%ori
    elif type(ori) == type(1):
        return 'make_CFNum(%d)'%ori
    elif ori == True:
        return 'kCFBooleanTrue'
    elif ori == False:
        return 'kCFBooleanFalse'
    utils.error('make_cfdic error')
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def mut(value, ty):
    nty = ''
    if ty in ['io_string_t', 'io_name_t']:
        ret = '{'
        for x in value[1:-1].split(','):
            ret += 'mut_byte(%s),'%x
        ret = ret[:-1]+'}'
        return ret
    elif '*' in ty or ty in const.TYPE_PTR:
        nty = 'ptr'
    elif ty in const.TYPE_SIZE:
        size = const.TYPE_SIZE[ty]
        if size == 1:
            nty = 'byte'
        elif size == 2:
            nty = 'short'
        elif size == 4:
            nty = 'int'
        elif size == 8:
            nty = 'long'
    if nty == '':
        utils.error('mut error : %s'%ty)

    return '(%s) mut_%s(%s)'%(ty, nty, str(value))
项目:SiteFab    作者:ebursztein    | 项目源码 | 文件源码
def clean_dir(directory):
    if os.path.exists(directory):
        shutil.rmtree(directory, ignore_errors=True)
    if os.path.exists(directory):
        utils.error("%s not deleted." % directory)
    os.mkdir(directory)
项目:build    作者:freenas    | 项目源码 | 文件源码
def check_build_sanity():
    if len(e('${BUILD_ROOT}')) > 38:
        error("Current path too long ({0} characters) for nullfs mounts during build",
              len(os.getcwd()))

    #if e('${BE_ROOT}/objs/ports') in sh_str('mount'):
    #    error("You have dangling mounts inside {0}, did last build crash?", e('${BE_ROOT}'))
项目:build    作者:freenas    | 项目源码 | 文件源码
def check_port(name, port):
    debug('Checking for "{0}" command', name)
    for i in e('${PATH}').split(':'):
        if os.path.exists(e('${i}/${name}')):
            return

    error('Command {0} not found. Please run "pkg install {1}" or install from ports', name, port)
项目:build    作者:freenas    | 项目源码 | 文件源码
def check_port_version(name, port, version):
    debug('Checking for version {0} of {1}', version, name)
    install_ver = os.popen("""pkg info -q | awk -F- '/%s/ {print $2}'"""
                           """| awk -F. '/%s/ {print $2}'""" % (name, version)).read().strip()
    if version != install_ver:
        error('Wrong version of {0} installed:', port)
项目:build    作者:freenas    | 项目源码 | 文件源码
def check_port_byfile(name, port, fname):
    debug('Checking for "{0}"', name)
    if os.path.exists(fname):
        return

    error('{0} not found.  Please run "pkg install {1}" or install from ports', fname, port)
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def get_log(self,v):
        if v in self.log :
            return self.log[v]
        utils.error('get_log error')
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def get_limit(logs):
    limit = None
    for log in logs:
        with open(log, 'rb') as f:
            n = (len(f.read().split('\n'))-1)/2
            if limit == None :
                limit = n
            elif limit != n:
                utils.error('Invalid triaged logs')
    return limit
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def get(self, v):
        if v in self.__dict__:
            return self.__dict__[v]
        utils.error('Api get error: %s'%str(v))
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def get(self,v):
        if v in self.__dict__:
            return self.__dict__[v]
        utils.error('Arg get error: %s doesn\'t have %s'%(self.name,str(v)))
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def get_dataflow(self, n, ty):
        dataflow = self.dataflow
        if dataflow != None and len(dataflow) >0:
            mapi, idx = dataflow.keys()[-1]
            pos = dataflow[(mapi,idx)].keys()[0]
            if pos[1] == DATA:
                return '%s_%s[%d]'%(pos[0], mapi.get_post(), pos[2]) 
            elif pos[1] == VALUE:
                return '%s_%s'%(pos[0],mapi.get_post())
            else:
                utils.error('get_dataflow error')
        elif self.ori != None:
            return get_ori(self.ori, ty)
        return get_value(ty, str(self.raw[n]))
项目:IMF    作者:SoftSec-KAIST    | 项目源码 | 文件源码
def find_best(groups, n):
    before = None
    idx = 0
    while len(groups) != 0:
        before = groups
        groups = categorize(groups, idx)
        if pick_best(groups, n) == None:
            return pick_best(before, n), idx
        idx += 1
    utils.error('find_best error')