This repository has been archived by the owner on Mar 13, 2019. It is now read-only.
/
fabfile.py
97 lines (77 loc) · 2.44 KB
/
fabfile.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
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
"""
Most commands in here are custom to my
local or server config, they'll need to
be adjusted if you wish to use them
"""
from getpass import getpass
import os
from glob import glob
from fabric.api import task, env, cd, run, local, prefix
from PyPaste.models.pastes import Paste
from PyPaste.models.users import User
from PyPaste.utils import create_paste_url
env.hosts = ['paste.buttscicl.es']
@task
def deploy(remote='origin', branch='master'):
with cd('~/projects/PyPaste/'):
run('git pull %s %s' % (remote, branch))
with prefix('source ~/venvs/pypaste/bin/activate'):
run('pip install -r requirements.txt')
run('pkill -f --signal HUP "gunicorn: master \[PyPaste\]"')
@task
def test():
os.environ['PYPASTE_TESTING'] = '1'
local('nosetests -v')
os.environ.pop('PYPASTE_TESTING')
@task
def highlight_examples():
extensions = {
'py': 'python',
'json': 'json'
}
files = glob('/home/joe/git/PyPaste/PyPaste/views/api/v1/templates/examples/*')
files = [f for f in files if not f.endswith('.html')]
for f in files:
extension = f.rsplit('.', 1)[1]
local('{pygments} -f html -l {ext} -O {opt} -o {output} {input}'.format(
pygments='/home/joe/.venvs/pypaste/bin/pygmentize',
ext=extensions[extension],
opt='linenos=1,lineanchors=line,anchorlinenos=1',
input=f,
output=f.replace('.' + extension, '.html')
))
@task
def add_user(username=None):
if username is None:
username = raw_input('Username: ')
password = getpass('Password: ')
if User.new(username, password):
print 'Success.'
else:
print 'Failure, try again.'
@task
def shortlink_backfill():
cur = Paste._cursor()
cur.execute(
"""
SELECT * from pastes
WHERE shortlink is null
"""
)
pastes = cur.fetchall()
for paste in pastes:
if paste['unlisted']:
url = 'https://paste.buttscicl.es/u/' + paste['hash']
else:
url = 'https://paste.buttscicl.es/p/' + str(paste['id'])
shortlink = Paste.get_shortlink(url)
if shortlink is not None:
cur.execute(
"""
UPDATE pastes SET shortlink = %s
WHERE hash = %s
""", (shortlink, paste['hash'])
)
Paste.conn.commit()
print 'Done #' + str(paste['id'])
cur.close()