-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathcmdline.py
More file actions
115 lines (93 loc) · 3.73 KB
/
Copy pathcmdline.py
File metadata and controls
115 lines (93 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
"""
Created on 2020/5/8 2:24 PM
---------
@summary:
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
import re
import sys
from os.path import dirname, join
import os
import requests
from feapder.commands import create_builder
from feapder.commands import retry
from feapder.commands import shell
from feapder.commands import zip
HELP = """
███████╗███████╗ █████╗ ██████╗ ██████╗ ███████╗██████╗
██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
█████╗ █████╗ ███████║██████╔╝██║ ██║█████╗ ██████╔╝
██╔══╝ ██╔══╝ ██╔══██║██╔═══╝ ██║ ██║██╔══╝ ██╔══██╗
██║ ███████╗██║ ██║██║ ██████╔╝███████╗██║ ██║
╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
Version: {version}
Document: https://feapder.com
Usage:
feapder <command> [options] [args]
Available commands:
"""
NEW_VERSION_TIP = """
──────────────────────────────────────────────────────
New version available \033[31m{version}\033[0m → \033[32m{new_version}\033[0m
Run \033[33mpip install --upgrade feapder\033[0m to update!
"""
with open(join(dirname(dirname(__file__)), "VERSION"), "rb") as f:
VERSION = f.read().decode("ascii").strip()
def _print_commands():
print(HELP.rstrip().format(version=VERSION))
cmds = {
"create": "create project、spider、item and so on",
"shell": "debug response",
"zip": "zip project",
"retry": "retry failed request or item",
}
for cmdname, cmdclass in sorted(cmds.items()):
print(" %-13s %s" % (cmdname, cmdclass))
print('\nUse "feapder <command> -h" to see more info about a command')
def check_new_version():
try:
url = "https://pypi.org/simple/feapder/"
resp = requests.get(url, timeout=3, verify=False)
html = resp.text
last_stable_version = re.findall(r"feapder-([\d.]*?).tar.gz", html)[-1]
now_version = VERSION
now_stable_version = re.sub("-beta.*", "", VERSION)
if now_stable_version < last_stable_version or (
now_stable_version == last_stable_version and "beta" in now_version
):
new_version = f"feapder=={last_stable_version}"
if new_version:
version = f"feapder=={VERSION.replace('-beta', 'b')}"
tip = NEW_VERSION_TIP.format(version=version, new_version=new_version)
# 修复window下print不能带颜色输出的问题
if os.name == "nt":
os.system("")
print(tip)
except Exception as e:
pass
def execute():
try:
args = sys.argv
if len(args) < 2:
_print_commands()
check_new_version()
return
command = args.pop(1)
if command == "create":
create_builder.main()
elif command == "shell":
shell.main()
elif command == "zip":
zip.main()
elif command == "retry":
retry.main()
else:
_print_commands()
except KeyboardInterrupt:
pass
check_new_version()
if __name__ == "__main__":
execute()