-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
71 lines (54 loc) · 1.92 KB
/
Copy pathfabfile.py
File metadata and controls
71 lines (54 loc) · 1.92 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
import os
import datetime
import time
from fabric.api import task
from fabric.operations import local
from pooltime import scrape as scrapers
class TaskHelper:
@staticmethod
def serve():
local('cd %s && python pooltime/app.py' % os.path.dirname(__file__))
@staticmethod
def install():
local('cd %s && npm install && bower install' % os.path.join(os.path.dirname(__file__), 'pooltime/client'))
@staticmethod
def build():
local('cd %s && grunt build' % os.path.join(os.path.dirname(__file__), 'pooltime/client'))
local('rm -rf %s' % os.path.join(os.path.dirname(__file__), 'pooltime/static'))
local('mv %s %s' % (os.path.join(os.path.dirname(__file__), 'pooltime/client/dist/static'), os.path.join(os.path.dirname(__file__), 'pooltime')))
local('mv %s %s' % (os.path.join(os.path.dirname(__file__), 'pooltime/client/dist/index.html'), os.path.join(os.path.dirname(__file__), 'pooltime/templates')))
@task
def run(serve=True, install=False, build=False):
if true(install):
TaskHelper.install()
if true(build):
TaskHelper.build()
if true(serve):
TaskHelper.serve()
@task
def serve():
TaskHelper.serve()
@task
def install():
TaskHelper.install()
@task
def build():
TaskHelper.build()
@task
def scrape(week, scores=True, lines=False):
if true(scores):
scrapers.LiveScoresScraper().scrape(week)
if true(lines):
scrapers.LinesScraper().scrape(week)
@task
def backup(dir_name=os.path.join(os.path.dirname(__file__), 'db')):
file_name = ''.join(['pooltime_', current_timestamp(), '.sql'])
local('pg_dump -o pooltime > %s' % os.path.join(dir_name, file_name))
@task
def restore(backup):
local('psql pooltime < %s' % backup)
def current_timestamp():
ts = time.time()
return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%dT%H:%M:%S')
def true(o):
return o in ['True', 'true', True]