-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
- Loading branch information
Showing
7 changed files
with
293 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{# -*- coding: utf-8 -*- #} | ||
{% extends 'base.tmpl' %} | ||
{% block content %} | ||
<div class="page-header"> | ||
<h1 class="build-status-caption"><i class="build-status-icon fa fa-fw fa-cog"></i> Rebuild</h1> | ||
</div> | ||
|
||
<div class="progress"> | ||
<div class="progress-bar progress-bar-striped active" id="progressbar" role="progressbar" aria-valuenow="0" aria-valuemin"0" aria-valuemax="100" style="width: 0%;"> | ||
0% | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title"> | ||
<a data-toggle="collapse" href="#collapseOutput" aria-expanded="false" aria-controls="collapseOutput"><i class="fa fa-bars"></i> Advanced information</a> | ||
</h3></div> | ||
<div class="panel-body collapse" id="collapseOutput"> | ||
<h4>Build</h4> | ||
<pre><code id="outputb">Working...</code></pre> | ||
|
||
<h4>Unused files removed</h4> | ||
<pre><code id="outputo">Working...</code></pre> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} | ||
|
||
{% block extra_js %} | ||
<script> | ||
function set_bar(current, max) { | ||
max = max; | ||
perc = 100 * current / max; | ||
pb.attr('aria-valuenow', Math.ceil(perc)); | ||
pb.attr('style', 'width: ' + perc + '%'); | ||
pb.html(Math.ceil(perc) + '%'); | ||
if (current == max) { | ||
pb.removeClass('active'); | ||
} | ||
} | ||
|
||
$(document).ready(function() { | ||
pb = $('#progressbar'); | ||
fs = $('.build-status-icon'); | ||
fsc = $('.build-status-caption'); | ||
outb = $('#outputb'); | ||
outo = $('#outputo'); | ||
var intID = setInterval(function() { | ||
$.ajax({ | ||
"url": "/api/rebuild", | ||
"dataType": "json", | ||
}).done(function(data) { | ||
outb.html(data.build.out); | ||
outo.html(data.orphans.out); | ||
set_bar(data.build.milestone, data.build.total + 1); | ||
of = (data.orphans.status === true); | ||
if (of) { | ||
set_bar(1, 1); | ||
pb.addClass('progress-bar-success'); | ||
fs.removeClass('fa-cog'); | ||
fs.addClass('fa-check'); | ||
fsc.addClass('text-success'); | ||
clearInterval(intID); | ||
} | ||
if (data.build.status === false || data.orphans.status === false) { | ||
pb.addClass('progress-bar-danger'); | ||
fs.removeClass('fa-cog'); | ||
fs.addClass('fa-times'); | ||
fsc.addClass('text-danger'); | ||
} | ||
}); | ||
}, 500); | ||
}); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
## -*- coding: utf-8 -*- | ||
<%inherit file="base.tmpl"/> | ||
<%block name="content"> | ||
<div class="page-header"> | ||
<h1 class="build-status-caption"><i class="build-status-icon fa fa-fw fa-cog"></i> Rebuild</h1> | ||
</div> | ||
|
||
<div class="progress"> | ||
<div class="progress-bar progress-bar-striped active" id="progressbar" role="progressbar" aria-valuenow="0" aria-valuemin"0" aria-valuemax="100" style="width: 0%;"> | ||
0% | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title"> | ||
<a data-toggle="collapse" href="#collapseOutput" aria-expanded="false" aria-controls="collapseOutput"><i class="fa fa-bars"></i> Advanced information</a> | ||
</h3></div> | ||
<div class="panel-body collapse" id="collapseOutput"> | ||
<h4>Build</h4> | ||
<pre><code id="outputb">Working...</code></pre> | ||
|
||
<h4>Unused files removed</h4> | ||
<pre><code id="outputo">Working...</code></pre> | ||
</div> | ||
</div> | ||
|
||
</%block> | ||
|
||
<%block name="extra_js"> | ||
<script> | ||
function set_bar(current, max) { | ||
max = max; | ||
perc = 100 * current / max; | ||
pb.attr('aria-valuenow', Math.ceil(perc)); | ||
pb.attr('style', 'width: ' + perc + '%'); | ||
pb.html(Math.ceil(perc) + '%'); | ||
if (current == max) { | ||
pb.removeClass('active'); | ||
} | ||
} | ||
|
||
$(document).ready(function() { | ||
pb = $('#progressbar'); | ||
fs = $('.build-status-icon'); | ||
fsc = $('.build-status-caption'); | ||
outb = $('#outputb'); | ||
outo = $('#outputo'); | ||
var intID = setInterval(function() { | ||
$.ajax({ | ||
"url": "/api/rebuild", | ||
"dataType": "json", | ||
}).done(function(data) { | ||
outb.html(data.build.out); | ||
outo.html(data.orphans.out); | ||
set_bar(data.build.milestone, data.build.total + 1); | ||
of = (data.orphans.status === true); | ||
if (of) { | ||
set_bar(1, 1); | ||
pb.addClass('progress-bar-success'); | ||
fs.removeClass('fa-cog'); | ||
fs.addClass('fa-check'); | ||
fsc.addClass('text-success'); | ||
clearInterval(intID); | ||
} | ||
if (data.build.status === false || data.orphans.status === false) { | ||
pb.addClass('progress-bar-danger'); | ||
fs.removeClass('fa-cog'); | ||
fs.addClass('fa-times'); | ||
fsc.addClass('text-danger'); | ||
} | ||
}); | ||
}, 500); | ||
}); | ||
</script> | ||
</%block> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Comet CMS v0.6.0 | ||
# Copyright © 2014-2015 Chris Warrick, Roberto Alsina, Henry Hirsch et al. | ||
|
||
# Permission is hereby granted, free of charge, to any | ||
# person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the | ||
# Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the | ||
# Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice | ||
# shall be included in all copies or substantial portions of | ||
# the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import subprocess | ||
import os | ||
from rq import get_current_job | ||
from sys import executable | ||
from redis import StrictRedis | ||
|
||
|
||
def build(dbdata, sitedir): | ||
"""Build a site.""" | ||
oldcwd = os.getcwd() | ||
os.chdir(sitedir) | ||
db = StrictRedis(**dbdata) | ||
job = get_current_job(db) | ||
job.meta.update({'out': '', 'milestone': 0, 'total': 1, 'return': None, | ||
'status': None}) | ||
job.save() | ||
p = subprocess.Popen([executable, '-m', 'nikola', 'build'], | ||
stderr=subprocess.PIPE) | ||
|
||
milestones = { | ||
'done!': 0, | ||
'render_posts': 0, | ||
'render_pages': 0, | ||
'generate_rss': 0, | ||
'render_indexes': 0, | ||
'sitemap': 0 | ||
} | ||
out = [] | ||
|
||
while p.poll() is None: | ||
nl = p.stderr.readline() | ||
for k in milestones: | ||
if k in nl: | ||
milestones[k] = 1 | ||
out.append(nl) | ||
job.meta.update({'milestone': sum(milestones.values()), 'total': | ||
len(milestones), 'out': ''.join(out), 'return': None, | ||
'status': None}) | ||
job.save() | ||
|
||
out += p.stderr.readlines() | ||
|
||
out = ''.join(out) | ||
job.meta.update({'milestone': len(milestones), 'total': len(milestones), | ||
'out': ''.join(out), 'return': p.returncode, 'status': | ||
p.returncode == 0}) | ||
job.save() | ||
os.chdir(oldcwd) | ||
return p.returncode | ||
|
||
|
||
def orphans(dbdata, sitedir): | ||
"""Remove all orphans in the site.""" | ||
oldcwd = os.getcwd() | ||
os.chdir(sitedir) | ||
db = StrictRedis(**dbdata) | ||
job = get_current_job(db) | ||
job.meta.update({'out': '', 'return': None, 'status': None}) | ||
job.save() | ||
p = subprocess.Popen([executable, '-m', 'nikola', 'orphans'], | ||
stdout=subprocess.PIPE) | ||
p.wait() | ||
files = [l.strip() for l in p.stdout.readlines()] | ||
for f in files: | ||
if f: | ||
os.unlink(f) | ||
|
||
out = '\n'.join(files) | ||
job.meta.update({'out': ''.join(out), 'return': p.returncode, 'status': | ||
p.returncode == 0}) | ||
job.save() | ||
os.chdir(oldcwd) | ||
return p.returncode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.