def main(config_dir):
    with open(os.path.join(config_dir, 'config.yaml'), 'r', 'utf8') as cfg_f:
        cfg = yaml.load(cfg_f)

        build_dir = cfg['output_dir']
        if not os.path.isabs(build_dir):
            build_dir = os.path.join(config_dir, build_dir)
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        j2 = j.Environment(loader=j.FileSystemLoader(TEMPLATES_DIR),
                           trim_blocks=True)

        generated = []
        navs = []
        index = None

        for p in PLUGINS:
            plugin_obj = p(config_dir=config_dir)
            pages = plugin_obj.generate()

            for page in pages:
                navbar = page.get('navbar', None)
                if navbar is not None:
                    navs.append({'name': navbar['name'], 'link': page['file']})
                    if navbar.get('index', False):
                        index = page['file']

            generated.append(pages)

        if index is None:
            raise Exception('Please specify one index page')

        def generate_final_page(content):
            return j2.get_template('index.html').render(
                title=cfg['title'],
                footer_content=cfg['footer_content'],
                content=content,
                navs=navs)

        for g in generated:
            for page in g:
                if bool(page.get('multiple', False)):
                    for _p in page['pages']:
                        html = generate_final_page(_p['html'])
                        write_page(build_dir, _p['file'], md5(html), html)

                else:
                    html = generate_final_page(page['html'])
                    write_page(build_dir, page['file'], md5(html), html)

        copyfile(os.path.join(build_dir, index),
                 os.path.join(build_dir, 'index.html'))
예제 #2
0
파일: setting.py 프로젝트: samshuai/Hawkeye
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('username', type=str, help='')
     parser.add_argument('password', type=str, help='')
     parser.add_argument('token', type=str, help='')
     args = parser.parse_args()
     username = args.get('username')
     password = args.get('password')
     token = args.get('token')
     try:
         g = Github(username, token)
         github_col.save({
             '_id':
             md5(username),
             'username':
             username,
             'password':
             password,
             'token':
             token,
             'mask_password':
             password.replace(''.join(password[2:-2]), '****'),
             'addat':
             timestamp(),
             'rate_limit':
             int(g.get_rate_limit().search.limit),
             'rate_remaining':
             int(g.get_rate_limit().search.remaining)
         })
         result = list(github_col.find({}, {'_id': 0}))
         data = {'status': 201, 'msg': '添加成功', 'result': result}
     except BadCredentialsException:
         data = {'status': 401, 'msg': '认证失败,请检查账号是否可用', 'result': []}
     return jsonify(data)
예제 #3
0
파일: setting.py 프로젝트: samshuai/Hawkeye
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('mail', type=str, help='')
     args = parser.parse_args()
     mail = args.get('mail')
     mail = mail.strip().replace(' ', '')
     notice_col.insert_one({'_id': md5(mail), 'mail': mail})
     result = list(notice_col.find({}, {'_id': 0}))
     data = {'status': 201, 'msg': '添加成功', 'result': result}
     return jsonify(data)
예제 #4
0
파일: setting.py 프로젝트: samshuai/Hawkeye
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('text', type=str, help='')
     args = parser.parse_args()
     text = args.get('text')
     text = text.strip().replace(' ', '')
     blacklist_col.save({'_id': md5(text), 'text': text})
     result = list(blacklist_col.find({}, {'_id': 0}))
     data = {'status': 201, 'msg': '添加成功', 'result': result}
     return jsonify(data)
예제 #5
0
def do_add():
    '''保存用户信息'''
    from model import member_props
    member = find_member({'passport':request.forms.get('passport')}) or {}
    for prop in member_props:
        if prop in request.forms:
            member[prop] = request.forms.get(prop)
    #hash password
    passwd_str = request.forms.get('password') if request.forms.get('password') else request.forms.get('passport')[-6:]
    member['password'] = md5(passwd_str)
    save_member(member)
    redirect('/manage/member/list')
예제 #6
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('keyword', type=str, help='')
     parser.add_argument('tag', type=str, help='')
     parser.add_argument('enabled', type=inputs.boolean, default=True, help='')
     args = parser.parse_args()
     if query_col.count({'tag': args.get('tag')}):
         query_col.update_one({'tag': args.get('tag')}, {'$set': args})
         msg = '更新成功'
     else:
         new_query = args
         new_query['_id'] = md5(''.join([str(v) for v in new_query.values()]))
         query_col.insert_one(new_query)
         msg = '添加成功'
     result = list(query_col.find({}).sort('enabled', -1))
     data = {'status': 200, 'msg': msg, 'result': result}
     return jsonify(data)
def write_page(build_dir, file, hash, html):
    path = os.path.join(build_dir, file)
    if os.path.exists(path):
        logger.info('File is already exists : %s', file)
        should_write = False
        with open(path, 'r', 'utf8') as f:
            if md5(f.read()) != hash:
                logger.info(
                    'Checksum is not matching, file will be overwritten')
                should_write = True
            else:
                logger.info('Checksum is matching')
        if should_write:
            with open(path, 'w', 'utf8') as f:
                f.write(html)
    else:
        logger.info('New file will be created : %s', file)
        with open(path, 'w', 'utf8') as f:
            f.write(html)
예제 #8
0
파일: passwd.py 프로젝트: lishuangye/python
#!/usr/bin/env python
# -*- encoding:utf-8 -*-

from utils.hash import md5
import sys

if __name__ == "__main__":
    string = sys.argv[1]

    print "str=", string
    print "hash=", md5(string)
예제 #9
0
#!/usr/bin/env python
# -*- encoding:utf-8 -*-

from utils.hash import md5
import sys

if __name__ == '__main__':
    string = sys.argv[1]

    print 'str=', string
    print 'hash=', md5(string)