python类GREEN的实例源码

qoqa.py 文件源码 项目:python3-qoqa 作者: ebsuku 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def create(project_name: str):
    """
    Launch interactive console and setup new project
    """
    if project_name in ['new', 'build', 'release']:
        print(Fore.RED + '[qoqa] invalid project name: {}'.format(project_name))
        exit()
    print("[qoqa] Configuring New Django Project")
    if os.path.isdir(project_name):
        print(Fore.RED + "[qoqa] project directory already exists")
        exit()
    db.setup()
    os.mkdir(project_name)
    os.chdir(project_name)
    virtualenv.create(project_name)
    development_config(project_name)
    production_config(project_name)
    print(Fore.GREEN + "[qoqa] Project {} has been setup".format(project_name))
virtualenv.py 文件源码 项目:python3-qoqa 作者: ebsuku 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _startproject(self, context):
        """
        Create a new django project
        """
        dj_admin_script = os.path.join(context.bin_path, 'django-admin')
        print(Fore.GREEN + "[qoqa] initializing django project")
        subprocess.run([
            dj_admin_script,
            'startproject',
            '--template='+template_zip,
            self._project_name])

        print(Fore.GREEN + "[qoqa] django project directory created")
        os.chdir(self._project_name)
        with open('__init__.py', 'a'):
            pass
        os.chmod('manage.py', stat.S_IRWXU)
build.py 文件源码 项目:python3-qoqa 作者: ebsuku 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def dpkg(version):
    """
    Start the build process
    """
    try:
        subprocess.run([
            'dch',
            '-r',
            version
        ], check=True)
    except subprocess.CalledProcessError as error:
        print(Fore.RED + "[qoqa] unable to release project")
        print(Fore.RED + "[qoqa] {}".format(error))
        exit()
    try:
        subprocess.run([
            'dpkg-buildpackage',
            '-us',
            '-uc'
        ], check=True)
    except subprocess.CalledProcessError as error:
        print(Fore.RED + "[qoqa] unable to releaseproject")
        print(Fore.RED + '[qoqa] {}'.format(error))
        exit()
    print(Fore.GREEN + "[qoqa] django project built")
database.py 文件源码 项目:python3-qoqa 作者: ebsuku 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def development_postgresql():
    """
    Setup development configurations for postgresql database
    """
    host = input(Fore.GREEN + 'Database Host: ')
    name = input(Fore.GREEN + 'Database Name: ')
    port = input(Fore.GREEN + 'Database Port: ')
    user = input(Fore.GREEN + 'Database User: ')
    password = input(Fore.GREEN + "Database Password: ")
    if '' in [host, name, user, password, port]:
        print(Fore.RED + "Please enter all database details")
        development_postgresql()
    else:
        qoqa.INIT_PROJECT_CONFIG['DEV_DB'] = {
            'DATABASE': 'postgresql',
            'HOST': host,
            'NAME': name,
            'USER': user,
            'PASSWORD': password,
            'PORT': port,
        }
post_actions.py 文件源码 项目:spotifyripper-gui 作者: mrhysjones 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create_playlist_m3u(self, tracks):
        args = self.args
        ripper = self.ripper

        name = self.get_playlist_name()
        if name is not None and args.playlist_m3u:
            name = sanitize_playlist_name(to_ascii(name))
            _base_dir = base_dir()
            playlist_path = to_ascii(
                os.path.join(_base_dir, name + '.m3u'))

            print(Fore.GREEN + "Creating playlist m3u file " +
                  playlist_path + Fore.RESET)

            encoding = "ascii" if args.ascii else "utf-8"
            with codecs.open(enc_str(playlist_path), 'w', encoding) as playlist:
                for idx, track in enumerate(tracks):
                    track.load()
                    if track.is_local:
                        continue
                    _file = ripper.format_track_path(idx, track)
                    if path_exists(_file):
                        playlist.write(os.path.relpath(_file, _base_dir) +
                                       "\n")
stitch_utils.py 文件源码 项目:Stitch 作者: nathanlopez 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def print_green(string):
    if windows_client(): reinit()
    print (Fore.GREEN + Style.BRIGHT + string + Style.RESET_ALL)
    if windows_client(): deinit()
messages.py 文件源码 项目:spyking-circus 作者: spyking-circus 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_colored_header():
    return Fore.GREEN + get_header() + Fore.RESET
logging.py 文件源码 项目:engel 作者: Dalloriam 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def success(message):
    print(Fore.GREEN + "+ " + message)
cftool.py 文件源码 项目:cftool 作者: guilhermeleobas 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def compile_file (filename, language = None, args = ''):
    print (args)
    ret = compile.compile(filename, language = language, args = args)
    if ret['status'] == compile.COMPILATION_CODE.ERROR:
        print ('Compile: ' + Fore.RED + 'ERROR\n')
        print (ret['stderr'])
        exit(1)
    else:
        print ('Compile: ' + Fore.GREEN + 'OK\n')
cftool.py 文件源码 项目:cftool 作者: guilhermeleobas 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def print_output(obj):
    # to-do:
    # Error while executing code

    if obj['status'] != 0:
        print ( '~ Test #{} - '.format(obj['testcase']) + Fore.RED + 'ERROR')
        # In some cases the process spawn by cftool returns SIGSEGV (-11)
        # and process.stderr is empty
        if obj['stderr'] == '' and obj['status'] == -11:
            print ('Process exited with SIGSEGV, probably because of a segmentation fault')
        else:
            print (obj['stderr'])
        return

    # split time between numbers and letters
    m = re.split(r'(\d+)', obj['time'])
    if int(m[1]) >= 5 and m[2] in ['s', 'm', 'h']:
        print ( '~ Test #{} - '.format(obj['testcase']) + Fore.RED + '{}'.format(obj['time']) )
    else:
        print ( '~ Test #{} - {}'.format(obj['testcase'], obj['time']) )

    stdout = obj['stdout']
    expected = obj['expected']

    if compare_outputs(stdout, expected):
        print (Fore.GREEN + stdout)
        print ('')
    else:
        print (Fore.RED + stdout)
        print ('')
        print (Fore.LIGHTBLACK_EX + 'Expected:')
        print (Fore.LIGHTBLACK_EX + expected)
        print ('')
common_funs.py 文件源码 项目:identifiera-sarkasm 作者: risnejunior 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _compile_table(self, name):
        # for readability
        metrics = self.metrics[name]
        fn = metrics['fn']; fp = metrics['fp']; tp = metrics['tp']; tn = metrics['tn']

        pt = PrettyTable([Fore.GREEN + name + Style.RESET_ALL,'Predicted NO','Predicted YES','Total'])
        pt.add_row(['Actual NO',tn,fp,tn+fp])
        pt.add_row(['Actual YES',fn,tp,fn+tp])
        pt.add_row(['Total',tn+fn,fp+tp,''])
        pt.hrules = ALL

        rows = ['' for i in range(6)]
        rows[0] = pt.get_string(padding_width=5)
        rows[1] = "Accuracy: {:^1}{:<.2f}".format("", metrics['accuracy'])
        rows[2] = "Precision: {:^}{:<.2f}".format("", metrics['precision'])
        rows[3] = "Recall: {:^3}{:<.2f}".format("",   metrics['recall'])
        rows[4] = "F1-score: {:^1}{:<.2f}".format("", metrics['f1_score'])
        rows[5] = ""

        self.rows.extend(rows)
8080.py 文件源码 项目:8080py 作者: sadboyzvone 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def printHelp():
    print('\nThis ' + Fore.BLUE + 'Intel' + Fore.WHITE
          + ' 8080 assembler was made for ' + Fore.BLUE + 'Project '
          + Fore.YELLOW + 'Week' + Fore.WHITE + ' at my school.')
    print('It is written in ' + Fore.BLUE + 'Pyt' + Fore.YELLOW + 'hon'
          + Fore.WHITE)
    print('Modules: ' + Fore.RED + 'Co' + Fore.BLUE + 'lo'
          + Fore.YELLOW + 'ra' + Fore.GREEN + 'ma' + Fore.WHITE)
    print('\nPass a file path as an arguement.')


# Main function
debug.py 文件源码 项目:pythonVSCode 作者: DonJayamanne 项目源码 文件源码 阅读 88 收藏 0 点赞 0 评论 0
def print_to_stdout(level, str_out):
    """ The default debug function """
    if level == NOTICE:
        col = Fore.GREEN
    elif level == WARNING:
        col = Fore.RED
    else:
        col = Fore.YELLOW
    if not is_py3:
        str_out = str_out.encode(encoding, 'replace')
    print(col + str_out + Fore.RESET)


# debug_function = print_to_stdout
binarly_query.py 文件源码 项目:binarly-query 作者: binarlyhq 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def process_classify(options):
    if os.path.exists(options.files[0]):
        filelist = options.files
        if os.path.isdir(options.files[0]):
            filelist = get_filelist(filelist[0])

        result = BINOBJ.classify_files(
            filelist, upload_missing=options.u, status_callback=my_callback)
    else:
        result = BINOBJ.classify_hashes(options.files)

    if 'error' in result or result['status'] != 'done':
        print(Style.BRIGHT + Fore.RED + "Request failed")
    else:
        print("Classification Results:")

    reqid = result.get('results', None)
    if reqid is None:
        # the request failed before any files could be analyzed
        print(Style.BRIGHT + Fore.RED +
              "Fail reason: {0} (error code={1})".format(
                  result['error']['message'], result['error']['code']))
        return

    classify_data = []
    for key, value in result['results'].iteritems():
        status = Style.RESET_ALL + Fore.GREEN + "OK" + Style.RESET_ALL
        if 'error' in value:
            status = Fore.RED + value['error']['message'] + Style.RESET_ALL
        row = {'SHA1': key, 'label': value.get('label', '.'), 'family': value.get('family', '.'), 'Status': status}

        classify_data.append(row)

    if options.pretty_print:
        show_results(classify_data, pretty_print=options.pretty_print)
    else:
        print("-" * 100)
        for row in classify_data:
            show_row(row)
    return
test_markup.py 文件源码 项目:python-ansimarkup 作者: gvalkov 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_usertags():
    user_tags = {
        'info':  F.GREEN + S.BRIGHT,
        'info1': p('<g><b>'),
        'call': lambda: F.BLUE + B.RED
    }
    am = AnsiMarkup(tags=user_tags)

    assert am.parse('<info>1</info>') == F.GREEN + S.BRIGHT + '1' + S.RESET_ALL
    assert am.parse('<info>1</info>') == am.parse('<info1>1</info1>')
    assert am.parse('<call>1</call>') == F.BLUE  + B.RED + '1' + S.RESET_ALL
    assert am.strip('<info1>1</info1>') == '1'
aesthetics.py 文件源码 项目:BrundleFuzz 作者: carlosgprado 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def m_ok(self, m):
        m = '[OK] ' + m
        if COLORAMA:
            print Fore.GREEN + m
        else:
            print m
aesthetics.py 文件源码 项目:BrundleFuzz 作者: carlosgprado 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def m_ok(self, m):
        m = '[OK] ' + m
        if COLORAMA:
            print Fore.GREEN + m
        else:
            print m
aesthetics.py 文件源码 项目:BrundleFuzz 作者: carlosgprado 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def m_ok(self, m):
        m = '[OK] ' + m
        if COLORAMA:
            print Fore.GREEN + m
        else:
            print m
mailfail.py 文件源码 项目:MailFail 作者: m0rtem 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def tor_test():
    # Get Tor IP from wtfismyip
    try:
        with urllib.request.urlopen('https://wtfismyip.com/text') as response:
            html = response.read()
            print_out(Style.BRIGHT + Fore.GREEN + "Your Tor IP is: " + html.decode('utf-8'))
    except HTTPError as e:
        # do something
        print_out(Style.BRIGHT + Fore.RED + "Error code: " + str(e.code))
        exit(1)
    except URLError as e:
        # do something
        print_out(Style.BRIGHT + Fore.RED + "Reason: " + str(e.reason))
        exit(1)
status_media-gateways.py 文件源码 项目:python-ossi 作者: iskhomutov 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def print_major_alarms(mj):
    """
    Args:
        mj (int): Counts of major alarms

    Returns:
        str: Colorized information by using colorama
    """
    if mj > 0:
        return Back.RED + Fore.WHITE + str(mj) + Fore.RESET + Back.RESET
    else:
        return Fore.GREEN + str(mj) + Fore.RESET


问题


面经


文章

微信
公众号

扫码关注公众号