-
Notifications
You must be signed in to change notification settings - Fork 429
/
maintenance.py
executable file
·60 lines (51 loc) · 1.96 KB
/
maintenance.py
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
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
import time
# get version without importing
with open("django_tables2/__init__.py", "rb") as f:
VERSION = str(re.search('__version__ = "(.+?)"', f.read().decode()).group(1))
if sys.argv[-1] == "publish":
try:
import twine # noqa
import wheel # noqa
except ImportError:
print("Required to publish: pip install wheel twine")
os.system("python setup.py clean --all")
os.system("python setup.py sdist bdist_wheel --universal")
os.system(
f"twine upload dist/django-tables2-{VERSION}.tar.gz"
f" dist/django_tables2-{VERSION}-py2.py3-none-any.whl"
)
print(f"\nreleased [{VERSION}](https://pypi.org/project/django-tables2/{VERSION}/)")
sys.exit()
if sys.argv[-1] == "tag":
os.system(f"git tag -a v{VERSION} -m 'tagging v{VERSION}'")
os.system("git push --tags && git push origin master")
sys.exit()
if sys.argv[-1] == "screenshots":
def screenshot(url, filename="screenshot.png", delay=2):
print(f"Making screenshot of url: {url}")
chrome = subprocess.Popen(
["chromium-browser", "--incognito", "--headless", "--screenshot", url], close_fds=False
)
print(f"Starting to sleep for {delay}s...")
time.sleep(delay)
chrome.kill()
os.system(f"convert screenshot.png -trim -bordercolor White -border 10x10 {dest}")
os.remove("screenshot.png")
print(f"Saved file to {dest}")
images = {
"{url}/tutorial/": "docs/img/example.png",
"{url}/bootstrap/": "docs/img/bootstrap.png",
"{url}/bootstrap4/": "docs/img/bootstrap4.png",
"{url}/semantic/": "docs/img/semantic.png",
}
print(
"Make sure the devserver is running: \n cd example/\n PYTHONPATH=.. ./manage.py runserver --insecure\n\n"
)
for url, dest in images.items():
screenshot(url.format(url="http://localhost:8000"), dest)
sys.exit()