forked from sdss/marvin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
176 lines (141 loc) · 5.51 KB
/
tasks.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
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
171
172
173
174
175
176
# !usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Licensed under a 3-clause BSD license.
#
# @Author: Brian Cherinka
# @Date: 2017-06-10 16:46:40
# @Last modified by: Brian Cherinka
# @Last Modified time: 2018-01-12 15:32:27
from __future__ import print_function, division, absolute_import
import os
from invoke import Collection, task
DIRPATH = '/home/manga/software/git/manga/marvin'
MODULEPATH = '/home/manga/software/git/modulefiles'
@task
def clean_docs(ctx):
''' Cleans up the docs '''
print('Cleaning the docs')
ctx.run("rm -rf docs/sphinx/_build")
@task
def build_docs(ctx):
''' Builds the Sphinx docs '''
print('Building the docs')
os.chdir('docs/sphinx')
ctx.run("make html")
@task
def show_docs(ctx):
"""Shows the Sphinx docs"""
print('Showing the docs')
os.chdir('docs/sphinx/_build/html')
ctx.run('open ./index.html')
@task
def clean(ctx):
''' Cleans up the crap '''
print('Cleaning')
# ctx.run("rm -rf docs/sphinx/_build")
ctx.run("rm -rf htmlcov")
ctx.run("rm -rf build")
ctx.run("rm -rf dist")
@task(clean)
def deploy(ctx):
''' Deploy to pypi '''
print('Deploying to Pypi!')
ctx.run("python setup.py --noweb sdist bdist_wheel --universal")
# pre-registration is deprecated for new pypi releases [~July 2017]
# ctx.run("twine register dist/sdss-marvin-*.tar.gz")
# ctx.run("twine register dist/sdss_marvin-*-none-any.whl")
ctx.run("twine upload dist/*")
@task
def update_default(ctx, path=None, version=None):
''' Updates the default version module file'''
assert version is not None, 'A version is required to update the default version!'
assert path is not None, 'A path must be specified!'
# update default version
f = open('.version', 'r+')
data = f.readlines()
data[1] = 'set ModulesVersion "{0}"\n'.format(version)
f.seek(0, 0)
f.writelines(data)
f.close()
@task
def update_module(ctx, path=None, wrap=None, version=None):
''' Update a module file '''
assert version is not None, 'A version is required to update the module file!'
assert path is not None, 'A path must be specified!'
print('Setting up module files!')
os.chdir(path)
newfile = 'mangawork.marvin_{0}'.format(version) if wrap else version
oldfile = 'mangawork.marvin_2.1.3' if wrap else 'master'
searchline = 'marvin' if wrap else 'version'
ctx.run('cp {0} {1}'.format(oldfile, newfile))
f = open('{0}'.format(newfile), 'r+')
data = f.readlines()
index, line = [(i, line) for i, line in enumerate(data)
if 'set {0}'.format(searchline) in line][0]
data[index] = 'set {0} {1}\n'.format(searchline, version)
f.seek(0, 0)
f.writelines(data)
f.close()
# update the default version
update_default(ctx, path=path, version=newfile)
@task
def update_git(ctx, version=None):
''' Update the git package at Utah '''
assert version is not None, 'A version is required to checkout a new git repo!'
print('Checking out git tag {0}'.format(version))
verpath = os.path.join(DIRPATH, version)
# checkout and setup new git tag
os.chdir(DIRPATH)
ctx.run('git clone https://github.com/sdss/marvin.git {0}'.format(version))
os.chdir(verpath)
ctx.run('git checkout {0}'.format(version))
ctx.run('git submodule update --init --recursive')
# ctx.run('python -c "from get_version import generate_version_py; '
# 'generate_version_py(\'sdss-marvin\', {0}, False)'.format(version))
@task
def update_current(ctx, version=None):
''' Update the current symlink '''
assert version is not None, 'A version is required to update the current symlink!'
# reset the current symlink
os.chdir(DIRPATH)
ctx.run('rm current')
ctx.run('ln -s {0} current'.format(version))
@task
def switch_module(ctx, version=None):
''' Switch to the marvin module of the specified version and start it '''
assert version is not None, 'A version is required to setup Marvin at Utah!'
ctx.run('uwsgi --stop /home/www/sas.sdss.org/mangawork/marvin/pid/uwsgi_marvin2.pid')
ctx.run('module unload wrapmarvin')
ctx.run('module load wrapmarvin/mangawork.marvin_{0}'.format(version))
ctx.run('uwsgi /home/manga/software/git/manga/marvin/{0}/python/marvin/web/uwsgi_conf_files/uwsgi_marvin_mangawork.ini'.format(version))
@task
def setup_utah(ctx, version=None):
''' Setup the package at Utah and update the release '''
assert version is not None, 'A version is required to setup Marvin at Utah!'
# update git
update_git(ctx, version=version)
# update_current
update_current(ctx, version=version)
# update modules
marvin = os.path.join(MODULEPATH, 'marvin')
wrap = os.path.join(MODULEPATH, 'wrapmarvin')
update_module(ctx, path=marvin, version=version)
update_module(ctx, path=wrap, wrap=True, version=version)
# restart the new marvin
# switch_module(ctx, version=version)
print('Marvin version {0} is set up!\n'.format(version))
print('Please run ...\n stopmarvin \n module switch wrapmarvin '
'wrapmarvin/mangawork.marvin_{0} \n startmarvin \n'.format(version))
ns = Collection(clean, deploy, setup_utah)
docs = Collection('docs')
docs.add_task(build_docs, 'build')
docs.add_task(clean_docs, 'clean')
docs.add_task(show_docs, 'show')
ns.add_collection(docs)
updates = Collection('update')
updates.add_task(update_git, 'git')
updates.add_task(update_current, 'current')
updates.add_task(update_module, 'module')
updates.add_task(update_default, 'default')
ns.add_collection(updates)