This repository was archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathmanage.py
More file actions
170 lines (131 loc) · 4.45 KB
/
manage.py
File metadata and controls
170 lines (131 loc) · 4.45 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# coding: utf-8
import platform
import getpass
import glob
import logging
import logging.config
import os
import shutil
import subprocess
import zipfile
import click
from config import config
from crawl.crawler import Crawler
from fetch import prepare_db, fetch_user, update_fetch_info
from web import app
from export import export_all
logging.config.dictConfig(config.LOGGING_CONF)
logger = logging.getLogger(__name__)
@click.group()
def cli():
pass
@cli.command()
@click.option("-e", "--email", default="")
@click.option("-p", "--password", default="")
@click.option("-s", "--status", default=False, is_flag=True)
@click.option("-g", "--gossip", default=False, is_flag=True)
@click.option("-a", "--album", default=False, is_flag=True)
@click.option("-b", "--blog", default=False, is_flag=True)
@click.option("-r", "--refresh_count", default=False, is_flag=True)
@click.option("-u", "--uid", default=0)
def fetch(
email, password, status, gossip, album, blog, refresh_count, uid
): # pylint: disable=R0913
cookie = Crawler.load_cookie()
if not cookie or email or password:
if not email:
email = input("Input renren account email (aka. username@renren.com): ")
if not password:
password = getpass.getpass("Input renren password (will not show): ")
prepare_db()
config.crawler = Crawler(email, password, cookie)
uid = uid or config.crawler.uid
fetched = fetch_user(
uid,
fetch_status=status,
fetch_gossip=gossip,
fetch_album=album,
fetch_blog=blog,
)
if not fetched:
logger.info("nothing need to fetch, just test login")
if fetched or refresh_count:
update_fetch_info(uid)
@cli.command()
@click.option("-f", "--filename", default=config.BAK_OUTPUT_TAR)
def export(filename):
client_app = app.test_client()
export_all(filename, client_app)
@cli.command()
def lint():
lint_files = [
"crawl",
"config.py",
"export.py",
"fetch.py",
"manage.py",
"models.py",
"web.py",
]
subprocess.run(["flake8"] + lint_files, check=True)
subprocess.run(["pylint"] + lint_files, check=True)
def clean_env():
# temp file
for f in glob.glob("./**/.pyc", recursive=True):
logger.info("remove temp file %s", f)
os.remove(f)
for f in glob.glob("./**/.pyo", recursive=True):
logger.info("remove temp file %s", f)
os.remove(f)
for f in glob.glob("./**/*~", recursive=True):
logger.info("remove temp file %s", f)
shutil.rmtree(f)
for f in glob.glob("./**/__pycache__", recursive=True):
logger.info("remove temp file %s", f)
shutil.rmtree(f)
# release
logger.info("remove release build")
shutil.rmtree("build", ignore_errors=True)
logger.info("remove release dist")
shutil.rmtree("dist", ignore_errors=True)
for f in glob.glob("./**/*.spec", recursive=True):
logger.info("remove release spec file %s", f)
os.remove(f)
@cli.command()
@click.option("-n", "--release_name", default="renrenBackup")
def release(release_name):
clean_env()
logger.info("package manager.py with pyinstaller")
subprocess.run(["pyinstaller", "-F", "manage.py", "-n", "renrenBackup"], check=True)
subprocess.run(["pyinstaller", "-F", "gui.py", "-n", "renrenBackup_gui"], check=True)
logger.info("copy templates and static files")
shutil.copytree("./templates", "./dist/templates")
os.mkdir("./dist/static")
shutil.copytree("./static/css", "./dist/static/css")
shutil.copytree("./static/js", "./dist/static/js")
shutil.copytree("./static/gif", "./dist/static/gif")
logger.info("init log directory")
os.mkdir("./dist/log")
logger.info("copy README to dist")
shutil.copy("./README.md", "./dist/")
if platform.system() == 'Darwin':
release_name += '_macOS'
elif platform.system() == 'Windows':
release_name += "_Windows"
else:
release_name += "_other"
with zipfile.ZipFile(release_name + ".zip", "w") as fp:
os.rename("./dist", release_name)
for f in glob.glob(release_name + "/**/*", recursive=True):
fp.write(f)
os.rename(release_name, "./dist")
@cli.command()
def clean():
clean_env()
@cli.command()
@click.option("-h", "--host", default="127.0.0.1")
@click.option("-p", "--port", default=5000)
def runserver(host, port):
app.run(host=host, port=port)
if __name__ == "__main__":
cli()