예제 #1
0
def use_whiptail_mode():
    menu_list = [
        "Article manager", "Menu manager", "Build static page", "Setting",
        "=" * 25, "Exit"
    ]
    if upgrade.check_is_git():
        menu_list = [
            "Article manager", "Menu manager", "Build static page", "Upgrade",
            "Setting", "=" * 25, "Exit"
        ]
    while True:
        dialog.title = "Home"
        result = dialog.menu("Please select an action", menu_list)
        if result == "Exit":
            exit(0)
        if result == "Article manager":
            article_manager()
        if result == "Menu manager":
            menu_manager()
        if result == "Upgrade":
            upgrade_system()
        if result == "Build static page":
            from manage import build_static_page
            dialog.title = "Build static page"
            build_static_page.publish()
            time.sleep(0.5)
        if result == "Setting":
            from manage import setting
            setting.setting_menu()
예제 #2
0
def use_text_mode(args):
    if args.command == "qrcode":
        system_config = json.loads(file.read_file("./config/system.json"))
        from common import install_module
        install_module.install_and_import("qrcode_terminal")
        import qrcode_terminal
        if len(system_config["API_Password"]) == 0 or len(system_config["Project_URL"]) == 0:
            console.log("Error", "Check the API_Password and Project_URL configuration items")
            exit(1)
        try:
            password_md5 = json.loads(system_config["API_Password"])["hash_password"]
        except (ValueError, KeyError, TypeError):
            exit(1)
        console.log("Info", "Please use the client to scan the following QR Code")
        config_json = json.dumps({"url": system_config["Project_URL"], "password": password_md5})
        qrcode_terminal.draw(config_json)
        exit(0)
    if args.command == "upgrade":
        from manage import upgrade
        if upgrade.upgrade_check():
            if not args.yes:
                start_to_pull = input('Find new version, do you want to upgrade? [y/N]')
            if start_to_pull.lower() == 'yes' or start_to_pull.lower() == 'y' or args.yes:
                upgrade.upgrade_pull()
                exit(0)
        console.log("Info", "No upgrade found")
        exit(0)
    if args.command == "build-page":
        from manage import build_static_page
        build_static_page.publish()
        exit(0)
    from manage import build_rss, post_manage
    if args.command == "new":
        config = None
        if args.config is not None:
            config = json.loads(file.read_file(args.config))
        if config is None:
            print("Please enter the title of the article:")
            title = input().strip()
            if len(title) == 0:
                console.log("Error", "The title can not be blank.")
                exit(1)
            name = get.get_name(title)
            print("Please enter the slug [{}]:".format(name))
            name2 = input().strip()
            if len(name2) != 0:
                name = get.filter_name(name2)
            if os.path.exists("./document/{}.md".format(name)):
                console.log("Error", "File [./document/{}.md] already exists".format(name))
                exit(1)
        if len(name) != 0 and len(title) != 0:
            config = {"title": title, "name": name}
            post_manage.new_post(config, args.independent)
            build_rss.build_rss()
        exit(0)
    if args.command == "update":
        if post_manage.update_post():
            build_rss.build_rss()
        exit(0)
예제 #3
0
def git_publish():
    status = False
    sign = str(request.json["sign"])
    send_time = int(request.json["send_time"])
    if check_password("git_page_publish", sign, send_time):
        from manage import build_static_page
        status = build_static_page.publish()
    result = {"status": status}
    return jsonify(result)
예제 #4
0
def use_whiptail_mode():
    dialog.title = "SilverBlog management tool"
    menu_list = ["Article manager", "Menu manager", "Build static page", "Setting", "=========================", "Exit"]
    upgrade_text = None
    if os.path.exists("./.git"):
        upgrade_text = "Upgrade"
        upgrade_check = False
        last_fetch_time = 0
        if os.path.exists("./upgrade/last_fetch_time.json"):
            last_fetch_time = json.loads(file.read_file("./upgrade/last_fetch_time.json"))["last_fetch_time"]
        if upgrade.upgrade_check(False):
            upgrade_text = "⚠ Upgrade"
            upgrade_check = True
        if (time.time() - last_fetch_time) > 259200 and not upgrade_check:
            console.log("Info", "Checking for updates...")
            file.write_file("./upgrade/last_fetch_time.json", json.dumps({"last_fetch_time": time.time()}))
            if upgrade.upgrade_check():
                upgrade_text = "⚠ Upgrade"
        menu_list = ["Article manager", "Menu manager", "Build static page", upgrade_text, "Setting",
                     "=========================", "Exit"]
    while True:
        result = dialog.menu("Please select an action", menu_list)
        if result == "Exit":
            exit(0)
        if result == "Article manager":
            article_manager()
        if result == "Menu manager":
            menu_manager()
        if upgrade_text is not None:
            if result == upgrade_text:
                upgrade_system()
        if result == "Build static page":
            from manage import build_static_page
            dialog.title = "Build static page"
            build_static_page.publish()
            time.sleep(0.5)
        if result == "Setting":
            from manage import setting
            setting.setting_menu()
예제 #5
0
파일: menu.py 프로젝트: fossabot/silverblog
def use_whiptail_mode():
    dialog.title = "SilverBlog management tool"
    while True:
        menu_list = [
            "Article manager", "Build static page", "Upgrade", "Setting",
            "Exit"
        ]
        result = dialog.menu("Please select an action", menu_list)
        if result == "Exit":
            exit(0)
        if result == "Article manager":
            article_manager()
        if result == "Upgrade":
            upgrade()
        if result == "Build static page":
            from manage import build_static_page
            dialog.title = "Build static page"
            build_static_page.publish()
        if result == "Setting":
            from manage import setting
            setting.setting_menu()
        time.sleep(0.5)
예제 #6
0
def git_publish():
    from manage import build_static_page
    status = build_static_page.publish()
    return json.dumps({"status": status})
예제 #7
0
파일: menu.py 프로젝트: fossabot/silverblog
def use_text_mode(args):
    if args.command == "qrcode":
        system_config = json.loads(file.read_file("./config/system.json"))
        try:
            import qrcode_terminal
        except ImportError:
            console.log(
                "Error",
                "Please install the qrcode-terminal package to support this feature"
            )
            install_dependency = input(
                'Do you want to install qrcode-terminal now? [y/N]')
            if install_dependency.lower() == 'yes' or install_dependency.lower(
            ) == 'y':
                import os
                os.system("python3 -m pip install qrcode-terminal")
        if len(system_config["API_Password"]) == 0 or len(
                system_config["Project_URL"]) == 0:
            console.log(
                "Error",
                "Check the API_Password and Project_URL configuration items")
            exit(1)
        try:
            password_md5 = json.loads(
                system_config["API_Password"])["hash_password"]
        except (ValueError, KeyError, TypeError):
            exit(1)
        console.log("Info",
                    "Please use the client to scan the following QR Code")
        config_json = json.dumps({
            "url": system_config["Project_URL"],
            "password": password_md5
        })
        qrcode_terminal.draw(config_json)
        exit(0)
    if args.command == "upgrade":
        from manage import upgrade
        if upgrade.upgrade_check():
            start_to_pull = input(
                'Find new version, do you want to upgrade? [y/N]')
            if start_to_pull.lower() == 'yes' or start_to_pull.lower() == 'y':
                upgrade.upgrade_pull()
                exit(0)
        console.log("info", "No upgrade found")
        exit(0)
    if args.command == "build-page":
        from manage import build_static_page
        build_static_page.publish()
        exit(0)

    from manage import build_rss
    if args.command == "new":
        from manage import new_post
        config = None
        if args.config is not None:
            config = json.loads(file.read_file(args.config))
        if config is None:
            print("Please enter the title of the article:")
            title = input()
            if len(title) != 0:
                name = new_post.get_name(title)
            print("Please enter the slug [{}]:".format(name))
            name2 = input()
            if len(name2) != 0:
                name = name2
        if len(name) != 0 and len(title) != 0:
            config = {"title": title, "name": name}
            new_post.new_post_init(config, args.independent)
            build_rss.build_rss()
        exit(0)
    if args.command == "update":
        from manage import update_post
        if update_post.update():
            build_rss.build_rss()
        exit(0)
예제 #8
0
            backup.backup()
            exit(0)

        if args.command == "install_theme":
            custom = False
            name = args.name
            if args.custom is not None:
                custom = True
                name = args.custom
            from manage import theme
            theme.install_theme(name, custom)
            exit(0)

        if args.command == "build-page":
            from manage import build_static_page
            build_static_page.publish()
            exit(0)

        from manage import build_rss, post_manage, get
        if args.command == "new":
            config = None
            name = ""
            title = ""
            if args.config is not None:
                config = json.loads(file.read_file(args.config))
            if config is None:
                print("Please enter the title of the article:")
                title = input().strip()
                if len(title) == 0:
                    console.log("Error", "The title can not be blank.")
                    exit(1)