예제 #1
0
def notifyfiledownloadstatus(school_code, file_id, downloadstatus):
    """
    返回下载成功与否的信息
    :param school_code: 
    :param file_id: 
    :param downloadstatus: 
    :return: 
    """
    try:
        url_notify = '/'.join([config.Config.SERVER_URL, 'notify'])
        json_str = json.dumps({
            'code': school_code,
            'downloadstatus': downloadstatus,
            'itemid': file_id
        })
        sign_str = ''.join([json_str, config.Config.HASH_KEY])
        signature = hashlib.md5(sign_str).hexdigest()
        params = {'json': json_str, 'signature': signature}
        r = requests.post(url_notify, data=params)
        gen_log.info('downloadfile url: %s, params: %s, response: %s',
                     url_notify, json.dumps(params, ensure_ascii=True), r.text)
        responde = r.json()
        respondecode = responde["respcode"]
        if respondecode == "00":
            return True
        else:
            return False

    except Exception:
        gen_log.exception("通知异常:")
        return False
예제 #2
0
def downloadfile(school_code, file_id, filename):
    """
    下载指定文件
    :param school_code: 学校编码
    :param file_id: 文件ID
    :param filename: 本地文件名
    :return: 
    """
    try:
        url_fileinfo = '/'.join([config.Config.SERVER_URL, 'downloadFile'])
        json_str = json.dumps({'code': school_code, 'itemid': file_id})
        sign_str = ''.join([json_str, config.Config.HASH_KEY])
        signature = hashlib.md5(sign_str).hexdigest()
        params = {"json": json_str, "signature": signature}
        r = requests.post(url_fileinfo, data=params, stream=True)
        gen_log.info('downloadfile url: %s, params: %s, response: %s',
                     url_fileinfo, json.dumps(params,
                                              ensure_ascii=True), r.text)

        f = open(filename, "wb")
        for chunk in r.iter_content(chunk_size=512):
            if chunk:
                f.write(chunk)
        return True
    except Exception:
        gen_log.exception('下载文件异常:')
        return False
예제 #3
0
def getfilelist(school_code):
    """
    获取待下载文件列表信息
    :param school_code: 
    :return: 
    """
    try:
        url_filelist = '/'.join([config.Config.SERVER_URL, 'getFileList'])
        json_str = json.dumps({'code': school_code})
        sign_str = ''.join([json_str, config.Config.HASH_KEY])
        signature = hashlib.md5(sign_str).hexdigest()
        params = {"json": json_str, "signature": signature}
        r = requests.post(url_filelist, data=params)
        gen_log.info('getfilelist url: %s, params: %s, response: %s',
                     url_filelist, json.dumps(params,
                                              ensure_ascii=True), r.text)

        response = r.json()
        if response['respcode'] == '00':
            filelist = response['filelist']
            return filelist
        else:
            gen_log.error(u'调用获取文件列表接口失败:%s', response['respdesc'])
            return None
    except Exception:
        gen_log.exception(u'调用获取文件列表接口异常:')
        return None
예제 #4
0
def uninstall():  # 检查并卸载已安装的服务
    if os_dist == 'centos':
        cha = subprocess.Popen("rpm -qa | grep mysql",
                               stdout=subprocess.PIPE,
                               shell=True)
        output1 = cha.communicate()[0]
        print output1
        if output1.strip() == '':
            print 'none mysql'
        else:
            a = raw_input("注意看--------请输入Y确认卸载数据库!!!!!!!!!!!!:\n" * 20)
            if a == 'Y':
                subprocess.call(['yum', 'erase', '-y', '*mysql-*'])
                print 'removed mysql'
            else:
                exit()
        chb = subprocess.Popen("rpm -qa | grep jdk",
                               stdout=subprocess.PIPE,
                               shell=True)
        output2 = chb.communicate()[0]
        print output2
        gen_log.info('where  jdk: %s', output2)
        if output2.strip() == '':
            print 'none jdk'
        else:
            a = raw_input("注意看--------请输入Y确认卸载JDK!!!!!!!!!!!!:\n" * 20)
            if a == 'Y':
                subprocess.call(['yum', 'remove', '-y', '*jdk*'])
                gen_log.info('remove jdk')
            else:
                exit()
    elif os_dist == 'Ubuntu':
        dse = subprocess.Popen("aptitude search '~i|~M' -F '%p' | grep mysql",
                               stdout=subprocess.PIPE,
                               shell=True)
        output3 = dse.communicate()[0]
        if output3.strip() == '':
            print 'none mysql'
        else:
            a = raw_input("注意看--------请输入Y确认卸载数据库!!!!!!!!!!!!:\n" * 20)
            if a == 'Y':
                subprocess.call(['apt-get', 'purge', '-y', 'mysql*.*'])
            else:
                exit()
        dsj = subprocess.Popen("aptitude search '~i|~M' -F '%p' | grep jdk",
                               stdout=subprocess.PIPE,
                               shell=True)
        output4 = dsj.communicate()[0]
        if output4.strip() == '':
            print 'none jdk'
        else:
            a = raw_input("注意看--------请输入Y确认卸载JDK!!!!!!!!!!!!:\n" * 20)
            if a == 'Y':
                subprocess.call(['apt-get', 'purge', '-y', 'jdk*.*'])
            else:
                exit()
예제 #5
0
def setup(script_name=''):
    Subject.Subject_name
    settings.define_app_options()
    self_dir = os.path.dirname(os.path.abspath(__file__))
    parse_command_line(final=False)
    conf_filename = "server.conf"
    if not options.debug:
        conf_filename = "prod.conf"
    conf_filename = os.path.join(os.path.dirname(self_dir), conf_filename)
    if os.path.exists(conf_filename):
        parse_config_file(conf_filename, final=False)
    else:
        print 'no {} found. skip it'.format(conf_filename)
    parse_command_line(final=True)
    setup_log(options)

    dbs = {}
    for subject in Subject.Subject_name:
        dbs[subject] = MongoClient(options.mongodb_host,
                     replicaSet=options.replica_set)[options[subject+'db_name']]
        print 'Connected to '+subject+'db ', options.mongodb_host

    env = Env
    env.db = dbs
    env.tc = {}
    env.deeprender_host = options.deeprender_host

    env.subject = Subject.get('math')

    if not options.debug:
        channel = logging.StreamHandler(sys.stdout)
        channel.setFormatter(LogFormatter())
        logging.getLogger().addHandler(channel)

    gen_log.info("Env was setup for %s. Subject: %s", script_name, env.subject.zh_name)

    return env
예제 #6
0
    def load_data(path):
        with open(path) as f:
            data = f.read()
            gen_log.info("log file " + path + " successfully")

        return data