Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1654 from shanzi/md
Add a proxy to use the API entries of nine.buildbot.net
- Loading branch information
Showing
7 changed files
with
197 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
|
||
import os | ||
import jinja2 | ||
|
||
from buildbot.test.fake import fakemaster | ||
from buildbot.util import in_reactor | ||
from buildbot.util import json | ||
from twisted.internet import defer | ||
from buildbot.www.config import IndexResource | ||
from buildbot.www.service import WWWService | ||
|
||
|
||
@in_reactor | ||
@defer.inlineCallbacks | ||
def processwwwindex(config): | ||
master = yield fakemaster.make_master() | ||
master_service = WWWService(master) | ||
|
||
if not config.get('index-file'): | ||
print "Path to the index.html file is required with option --index-file or -i" | ||
defer.returnValue(1) | ||
path = config.get('index-file') | ||
if not os.path.isfile(path): | ||
print "Invalid path to index.html" | ||
defer.returnValue(2) | ||
|
||
main_dir = os.path.dirname(path) | ||
|
||
for name in master_service.apps.names: | ||
if name != 'base': | ||
pluginapp = master_service.apps.get(name) | ||
try: | ||
os.symlink(pluginapp.static_dir, os.path.join(main_dir, name)) | ||
except OSError: | ||
pass | ||
|
||
plugins = dict((k, {}) for k in master_service.apps.names if k != "base") | ||
|
||
fakeconfig = {"user": {"anonymous": True}} | ||
fakeconfig['buildbotURL'] = master.config.buildbotURL | ||
fakeconfig['title'] = master.config.title | ||
fakeconfig['titleURL'] = master.config.titleURL | ||
fakeconfig['multiMaster'] = master.config.multiMaster | ||
fakeconfig['versions'] = IndexResource.getEnvironmentVersions() | ||
fakeconfig['plugins'] = plugins | ||
outputstr = '' | ||
with open(path) as indexfile: | ||
template = jinja2.Template(indexfile.read()) | ||
outputstr = template.render(configjson=json.dumps(fakeconfig), config=fakeconfig) | ||
with open(path, 'w') as indexfile: | ||
indexfile.write(outputstr) | ||
defer.returnValue(0) |
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,61 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
|
||
import tempfile | ||
|
||
from twisted.trial import unittest | ||
|
||
from buildbot.util import json | ||
from buildbot.scripts import processwwwindex | ||
|
||
|
||
class TestUsersClient(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# un-do the effects of @in_reactor | ||
self.patch(processwwwindex, 'processwwwindex', processwwwindex.processwwwindex._orig) | ||
|
||
def test_no_input_file(self): | ||
d = processwwwindex.processwwwindex({}) | ||
|
||
def check(ret): | ||
self.assertEqual(ret, 1) | ||
d.addCallback(check) | ||
return d | ||
|
||
def test_invalid_input_file(self): | ||
d = processwwwindex.processwwwindex({'index-file': '/some/no/where'}) | ||
|
||
def check(ret): | ||
self.assertEqual(ret, 2) | ||
d.addCallback(check) | ||
return d | ||
|
||
def test_output_config(self): | ||
tmpf = tempfile.NamedTemporaryFile(suffix=".html") | ||
with open(tmpf.name, 'w') as f: | ||
f.write('{{ configjson|safe }}') | ||
|
||
d = processwwwindex.processwwwindex({'index-file': tmpf.name}) | ||
|
||
def check(ret): | ||
self.assertEqual(ret, 0) | ||
with open(tmpf.name) as f: | ||
config = json.loads(f.read()) | ||
self.assertTrue(isinstance(config, dict)) | ||
|
||
d.addCallback(check) | ||
return d |
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
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