-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
271 lines (218 loc) · 5.83 KB
/
tasks.py
File metadata and controls
271 lines (218 loc) · 5.83 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# -*- coding: utf-8 -*-
'''inv matter for auto pub. 101.camp
'''
__version__ = 'pub101CAMP v.190721.2342'
__author__ = 'Zoom.Quiet'
__license__ = 'MIT@2019-04'
#import io
import os
#import re
import sys
import time
#import datetime
#import json
#import marshal as msh
#import subprocess
#import logging
#import sys
import logging
#logging.basicConfig()
logging.basicConfig(level=logging.CRITICAL)
_handler = logging.StreamHandler()
_formatter = logging.Formatter("[%(levelname)s]%(asctime)s:%(name)s(%(lineno)s): %(message)s"
#, datefmt='%Y.%m.%d %H:%M:%S'
, datefmt='%H:%M:%S'
)
_handler.setFormatter(_formatter)
LOG = logging.getLogger(__name__)
#LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
LOG.propagate = False
LOG.addHandler(_handler)
#LOG.debug('load LOG level')
from pprint import pprint as pp
#pp = pprint.PrettyPrinter(indent=4)
from pprint import pformat
#import platform
#os_name = platform.system()
#del platform
#import subprocess
from invoke import task
#from fabric.context_managers import cd
from textwrap import dedent as dedentxt
CAMPROOT = os.environ.get("CAMPSITES_ROOT")
CSITES = {'mk':{'gl':'mk'
, 'ghp':'mk.101.camp'
, 'log': None
}
}
AIM = 'site'
_TRIP = '_trigger'
_TOBJ = 'deploy.md'
TRIGGER = 0
@task
def ver(c):
'''echo crt. verions
'''
print('\n\t powded by {}'.format(__version__))
# support stuff func.
def cd(c, path2):
os.chdir(path2)
print('\n\t crt. PATH ===')
c.run('pwd')
#@task
def ccname(c):
c.run('cp CNAME %s/'% AIM, hide=False, warn=True)
c.run('ls %s/'% AIM, hide=False, warn=True)
c.run('pwd')
#@task
def sync4media(c):
c.run('cp -rvf img %s/'% AIM, hide=False, warn=True)
c.run('ls %s/'% AIM, hide=False, warn=True)
c.run('pwd')
@task
def pl(c, site):
'''$ inv pl [101|py] <- pull all relation repo.
'''
global CAMPROOT
global CSITES
print(CAMPROOT)
if site:
#pp(CSITES[site])
_aim = '%s/%s'%(CAMPROOT, CSITES[site]['gl'])
cd(c, _aim)
#os.chdir(_aim)
#c.run('pwd')
c.run('git pull', hide=False, warn=True)
_aim = '%s/%s'%(CAMPROOT, CSITES[site]['ghp'])
cd(c, _aim)
#os.chdir(_aim)
#c.run('pwd')
c.run('git pull', hide=False, warn=True)
else:
ver(c)
@task
def bu(c):
'''usgae MkDocs build AIM site
'''
c.run('pwd')
c.run('mkdocs build', hide=False, warn=True)
@task
def pu(c):
'''push gl manuscript...
'''
_ts = '{}.{}'.format(time.strftime('%y%m%d %H%M %S')
, str(time.time()).split('.')[1][:3] )
c.run('pwd')
c.run('git st', hide=False, warn=True)
#c.run('git add .', hide=False, warn=True)
#c.run('git ci -am '
c.run('git imp '
'"inv(loc) MkDocs upgraded by DAMA (at %s)"'% _ts
, hide=False, warn=True)
#c.run('git pu', hide=False, warn=True)
# 'rsync -avzP4 {static_path}/media/ {deploy_path}/media/ && '
#@task
def ghp(c, site):
'''$ inv gh [101|py] <- push gh-pages for site publish
'''
global CAMPROOT
global CSITES
print(CAMPROOT)
ccname(c)
sync4media(c)
_ts = '{}.{}'.format(time.strftime('%y%m%d %H%M %S')
, str(time.time()).split('.')[1][:3] )
_aim = '%s/%s'%(CAMPROOT, CSITES[site]['ghp'])
cd(c, _aim)
#os.chdir(AIM)
#with cd('site/'):
#c.run('pwd')
c.run('ls')
c.run('git st', hide=False, warn=True)
#c.run('git add .', hide=False, warn=True)
#c.run('git ci -am '
c.run('git imp '
'"pub(site) gen. by MkDocs as invoke (at %s)"'% _ts
, hide=False, warn=True)
#c.run('git pu', hide=False, warn=True)
#@task
def chktri(c):
'''check trigger obj. set TRIGGER switch
'''
global TRIGGER
global _TRIP, _TOBJ
#cd(c, '%s/%s/%s'%(_DU19, PUB, _TRI))
_path = './%s'% _TRIP
print(_path)
#print(os.listdir(_path))
#print(type(os.listdir(_path)))
if _TOBJ in os.listdir(_path):
print('TRIGGERed by %s exist'% _TOBJ)
TRIGGER = 1
else:
print('TRIGGER obj. -> %s ~> NOT exist\n\t CANCEL build...'% _TOBJ)
TRIGGER = 0
#@task
def recover(c):
'''recover trigger state, by del TRIGGER obj.
'''
global TRIGGER
global _TRIP, _TOBJ
#cd(c, '%s/%s/%s'%(_DU19, PUB, _TRI))
_path = './%s'% _TRIP
_obj = '%s/%s'%(_path, _TOBJ)
print(_obj)
c.run('rm -vf %s'% _obj)
c.run('ls -Aogh %s'% _path)
c.run('git st')
c.run('git fix "(pubDUW) recover trigger obj. wait NEXT deploy"')
TRIGGER = 0
print('TRIGGER obj. recover -> waiting human deploy again')
#@task
def gh(c):
'''push gh-pages for site publish
'''
#global CAMPROOT
#global CSITES
#print(CAMPROOT)
ccname(c)
sync4media(c)
_ts = '{}.{}'.format(time.strftime('%y%m%d %H%M %S')
, str(time.time()).split('.')[1][:3] )
#_aim = '%s/%s'%(CAMPROOT, CSITES[site]['ghp'])
cd(c, AIM)
#os.chdir(AIM)
#with cd('site/'):
#c.run('pwd')
c.run('ls')
c.run('git st', hide=False, warn=True)
#c.run('git add .', hide=False, warn=True)
#c.run('git ci -am '
c.run('git imp '
'"pub(site) gen. by MkDocs as invoke (at %s)"'% _ts
, hide=False, warn=True)
#c.run('git pu', hide=False, warn=True)
#def pub(c, site):
@task
def pub(c):
'''<- auto deploy new site version base multi-repo.
'''
#global TRIGGER
#global CAMPROOT
#global CSITES
#print(CAMPROOT)
#pl(c, site)
#_crt = '%s/%s'%(CAMPROOT, CSITES[site]['gl'])
#cd(c, _crt)
#chktri(c)
print('auto deplo NOW:')
#return None
bu(c)
#recover(c)
pu(c)
ccname(c)
#sync4media(c)
gh(c)
ver(c)
return None