Пример #1
0
def run_by_reason_only(repo,
                       file_or_directory,
                       recurse=True,
                       dryrun=False,
                       verbose=False,
                       autopep8=None,
                       errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"
                    ] + verbose_opt + recurse_opt

    i = 0
    for error_no, description in errors:
        cmd = autopep8_cmd + [
            "--select={0}".format(error_no), file_or_directory
        ]

        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(file_or_directory, error_no,
                                            description)
                repo.index.add([file_or_directory])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #2
0
def run_autopep8(repo,
                 file_or_directory,
                 recurse=True,
                 dryrun=False,
                 verbose=False,
                 autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #3
0
def run_by_file_only(repo,
                     file_or_directory,
                     recurse=True,
                     dryrun=False,
                     verbose=False,
                     autopep8=None,
                     errors=None):
    select_opt = (["--select={0}".format(",".join(errors))]
                  if errors != ERRORS else [])
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"
                    ] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #4
0
def run_by_file_only(repo,
                     file_or_directory, recurse=True,
                     dryrun=False, verbose=False, autopep8=None,
                     errors=None):
    select_opt = (
        ["--select={0}".format(",".join(errors))]
        if errors != ERRORS
        else []
    )
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #5
0
def stopAndDeleteContainer(containerId):
    command = 'cd ' + os.path.abspath('lua/') + ' && lua ' + os.path.abspath(
        'lua/dockerman.lua') + ' -D ' + containerId
    result = common.run_command(command)
    for res in result:
        if res == 0:
            #返回容器ID
            return 0
    return -1
Пример #6
0
def run_autopylint(file_or_directory, ext=".py", recurse=True,
                   dryrun=False, verbose=False, author=None):
    file_list = get_filelist(file_or_directory, recurse, ext)
    i = 0
    for fullpath, hash_before, error_no, error_comment in loop_params(file_list):
        cmd = ["autopylint", "--in-place", "--verbose",
               "--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if hash_before != sha1_file(fullpath):
                # I can't tell if autopep8 has modified a file from the return code,
                # so I do it the hard way...
                info(output)
                git_commit(
                    fullpath,
                    "{0} {1}".format(error_no, error_comment),
                    dryrun, verbose, author)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #7
0
def run_all(repo,
            file_or_directory, recurse=True,
            dryrun=False, verbose=False, autopep8=None,
            errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    select_opt = (
        ["--select={0}".format(",".join(errors))]
        if errors != ERRORS
        else []
    )
    verbose_opt = ["--verbose"] if verbose else []
    cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + recurse_opt + select_opt + [file_or_directory]

    if verbose or dryrun:
        info(" ".join(cmd))
    if not dryrun:
        output = run_command(cmd)
        if repo.is_dirty():
            info(output)
            msg = "autopep8 run on all {0}".format(file_or_directory)
            repo.index.add([file_or_directory])
            repo.index.commit(msg)
Пример #8
0
def run_autopep8(repo,
                 file_or_directory, recurse=True,
                 dryrun=False, verbose=False, autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #9
0
def run_all(repo,
            file_or_directory,
            recurse=True,
            dryrun=False,
            verbose=False,
            autopep8=None,
            errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    select_opt = (["--select={0}".format(",".join(errors))]
                  if errors != ERRORS else [])
    verbose_opt = ["--verbose"] if verbose else []
    cmd = [autopep8 or "autopep8", "--in-place"
           ] + verbose_opt + recurse_opt + select_opt + [file_or_directory]

    if verbose or dryrun:
        info(" ".join(cmd))
    if not dryrun:
        output = run_command(cmd)
        if repo.is_dirty():
            info(output)
            msg = "autopep8 run on all {0}".format(file_or_directory)
            repo.index.add([file_or_directory])
            repo.index.commit(msg)
Пример #10
0
def createAndStartContainer(cookie, tgUserId, name):
    ##lua newcontainer.lua -n jd_scripts_test -e \"JD_COOKIE=pt_key=AAJgSIA0ADC-1mV_7uCjZK2kIBxYN4sdb1L9PyAktQewf5Hse7QHaFJVBE3egdRZugQF0FeiWvI\;pt_pin=fangxueyidao\;\",\"RANDOM_DELAY_MAX=
    ##600\",\"TG_BOT_TOKEN=644204874\:AAETxq7Wr2-rXEijjKYJqn3vXsCijG6xm-w\",\"TG_USER_ID=490884842\",\"CUSTOM_SHELL_FILE=https://raw.githubusercontent.com/jianminLee/jd_scripts/main/docker_shell.sh\" -m \"/opt/jd_scri
    ##pts/logs:/scripts/logs\"
    ## 拼接参数
    n = env['jd_scripts']['docker_container_prefix'] + name
    e = '\\\"JD_COOKIE='+cookie.strip()+'\\\",\\\"RANDOM_DELAY_MAX=600\\\",\\\"TG_BOT_TOKEN=' \
        +env['jd_scripts']['tg_bot_token'] \
        +'\\\",\\\"TG_USER_ID='+str(tgUserId)+'\\\"'
    m = '\\\"/opt/jd_scripts/logs/' + str(tgUserId) + ':/scripts/logs\\\"'

    command = ("cd " + os.path.abspath('lua/') + " && lua " +
               os.path.abspath('lua/dockerman.lua') + " -n " + n + ' -e ' + e +
               ' -m ' + m + ' -d ' +
               env['jd_scripts']['existed_docker_container_id']).replace(
                   ';', '\\;')
    print(n + '\n' + e + '\n' + m + '\ncommand:' + command)
    result = common.run_command(command)
    for res in result:
        if res.startswith('id:'):
            #返回容器ID
            return res[3:]
    return -1
Пример #11
0
def run_by_reason_only(repo,
                       file_or_directory, recurse=True,
                       dryrun=False, verbose=False, autopep8=None,
                       errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + recurse_opt

    i = 0
    for error_no, description in errors:
        cmd = autopep8_cmd + ["--select={0}".format(error_no), file_or_directory]

        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(file_or_directory, error_no, description)
                repo.index.add([file_or_directory])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Пример #12
0
    def jd_login_command_callback(self, update: update, context):
        print('接收到 京东登陆命令')
        print('用户TG ID: ' + str(update.message.chat.id))
        ## docker数量超出
        if User.select().count() >= int(env['jd_scripts']['max_docker_num']):
            update.message.reply_text('用户数量已达上限:' +
                                      env['jd_scripts']['max_docker_num'])
            print('用户数量已达上限:' + env['jd_scripts']['max_docker_num'])
            return
        ## 判断管理员
        admins = env['telegram_bot']['admins'].split(',')
        if admins[0] == '' or str(update.message.chat.id) not in admins:
            update.message.reply_text('没有权限')
            print('没有权限')
            return
        ## 防止用户频繁发送登陆请求
        cache_name = self.cache_prefix + str(update.message.chat.id)
        if self.redis.get(cache_name):
            update.message.reply_text('请勿频繁提交登陆请求,每次登陆请求间隔三分钟或登陆成功!')
            print('请求频繁,拒绝请求')
            return
        self.redis.set(cache_name, 1)
        self.redis.expire(cache_name, datetime.timedelta(minutes=3))
        result = common.run_command([
            'docker exec -i ' +
            env['jd_scripts']['existed_docker_container_name'] +
            ' /bin/sh -c "node /scripts/getJDCookie.js"'
        ])

        login_qrcode_message = {}
        for res in result:
            if res.startswith('https://plogin.m.jd.com/cgi-bin'):
                qr = segno.make(res)
                print(qr)
                qr_img = io.BytesIO()
                qr.save(qr_img, kind='png', scale=10)
                login_qrcode_message = update.message.reply_photo(
                    qr_img.getvalue(), '京东APP扫描二维码登陆\n二维码有效期三分钟')
                continue
                ##{'message_id': 2593, 'date': 1615472636,
                # 'chat': {'id': 490884842, 'type': 'private', 'username': '******', 'first_name': 'Orz'},
                # 'entities': [], 'caption_entities': [],
                # 'photo': [{'file_id': 'AgACAgUAAxkDAAIKIWBKJ_zt2bRqqJZMiRVvHhI1_jcZAAItqzEb8q9YVs8ou--o8j7vKT8Xb3QAAwEAAwIAA3gAA37bAgABHgQ', 'file_unique_id': 'AQADKT8Xb3QAA37bAgAB', 'width': 490, 'height': 490, 'file_size': 30636},
                # {'file_id': 'AgACAgUAAxkDAAIKIWBKJ_zt2bRqqJZMiRVvHhI1_jcZAAItqzEb8q9YVs8ou--o8j7vKT8Xb3QAAwEAAwIAA20AA4DbAgABHgQ', 'file_unique_id': 'AQADKT8Xb3QAA4DbAgAB', 'width': 320, 'height': 320, 'file_size': 31843}],
                # 'new_chat_members': [], 'new_chat_photo': [], 'delete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created': False, 'channel_chat_created': False, 'from': {'id': 644204874, 'first_name': 'OrzLee', 'is_bot': True, 'username': '******'}}
                # print(login_qrcode_message, login_qrcode_message.chat.id)
            elif res.startswith('二维码已失效'):
                update.message.reply_text(res.strip())
                continue
            elif res.startswith('pt_key='):
                ##登陆成功
                if env['jd_scripts']['add_user_mode'] == 'attach':
                    ##附加cookie到容器
                    self.attachCookieToContainer(update=update,
                                                 cookie=res.strip())
                else:
                    self.createDockerContainer(update=update,
                                               cookie=res.strip())
                break

        # 删除二维码消息
        self.bot.delete_message(chat_id=login_qrcode_message.chat.id,
                                message_id=login_qrcode_message.message_id)