Skip to content

Commit

Permalink
Google app engine application to control automatic updates, initial r…
Browse files Browse the repository at this point in the history
…elease.

git-svn-id: https://radegast.googlecode.com/svn/misc/update_site@314 f7a694da-4d33-11de-9ad6-1127a62b9fcd
  • Loading branch information
[email protected] committed Oct 6, 2009
1 parent dbc8501 commit 0926c01
Show file tree
Hide file tree
Showing 21 changed files with 521 additions and 0 deletions.
68 changes: 68 additions & 0 deletions admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# $Id: $

import wsgiref.handlers
import cgi
import radupdater
from radupdater import Settings
from radupdater import UpdateInfo
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users

class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()

if user:
if not users.is_current_user_admin():
self.redirect(users.create_logout_url("/noaccess"))
return

if self.request.get("set_version") != "":
new_version = self.request.get('new_version')
if new_version != '':
settings = Settings(key_name = "current_version", value = new_version)
settings.put();


new_site = self.request.get("new_site")
if new_site != '':
settings = Settings(key_name = "current_site", value = new_site)
settings.put();

new_motd = self.request.get("new_motd")
if new_motd != '':
settings = Settings(key_name = "current_motd", value = new_motd)
settings.put();

new_display_motd = self.request.get("new_display_motd")
settings = Settings(key_name = "current_display_motd", value = ("false", "true")[new_display_motd != ""])
settings.put();

info = UpdateInfo()

self.response.out.write(
template.render('templates/adm_main.html', {
"version": cgi.escape(info.CurrentVersion),
"site": cgi.escape(info.DownloadSite),
"motd": cgi.escape(info.MOTD),
"display_motd": ("", " checked")[info.DisplayMOTD],
"logouturl": users.create_logout_url("/")
}))
return
else:
self.redirect(users.create_login_url(self.request.uri))
return


def main():
app = webapp.WSGIApplication([
(r'/admin/', MainHandler),
], debug=False)
wsgiref.handlers.CGIHandler().run(app)


if __name__ == '__main__':
main()

17 changes: 17 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
application: radegastupdate
version: 1
runtime: python
api_version: 1

handlers:
- url: /static
static_dir: static
- url: /favicon\.ico
static_files: static/favicon.ico
upload: static/favicon.ico
- url: /admin/.*
script: admin.py
- url: /svc/.*
script: svc.py
- url: .*
script: main.py
11 changes: 11 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
30 changes: 30 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
# $Id: $

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(
template.render('templates/main.html', {}))


class NoAccessHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(
template.render('templates/noaccess.html', {}))


def main():
app = webapp.WSGIApplication([
(r'/', MainHandler),
(r'/noaccess', NoAccessHandler),
], debug=False)
wsgiref.handlers.CGIHandler().run(app)


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions radegastupdate.kpf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="6757c891-d8cb-4dfd-852f-e1b7ccbac3ca" kpf_version="4" name="radegastupdate.kpf">
<file id="be5690c2-bd98-4907-9978-edc452bbf876" idref="6757c891-d8cb-4dfd-852f-e1b7ccbac3ca" name="app.yaml" url="app.yaml">
</file>
<preference-set idref="6757c891-d8cb-4dfd-852f-e1b7ccbac3ca">
<boolean id="import_live">1</boolean>
</preference-set>
<preference-set idref="be5690c2-bd98-4907-9978-edc452bbf876">
</preference-set>
</project>
55 changes: 55 additions & 0 deletions radupdater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
# $Id: radupdater.py 7 2009-09-22 14:20:21Z lkalif $

from google.appengine.ext import db
from django.utils import simplejson
from django.core import serializers

class Settings(db.Model):
value = db.StringProperty(required = True)

class Serializable:
def get_dict(self):
return dict((key, value) for key, value in self.__dict__.iteritems()
if not callable(value) and not key.startswith('__'))

def json(self):
return simplejson.dumps(self.get_dict(), sort_keys=True, indent=4)

class UpdateInfo(Serializable):
def __init__(self):
self.Error = False
self.ErrMessage = ''
self.CurrentVersion = ''
self.DownloadSite = ''
self.MOTD = ''
self.DisplayMOTD = False

setting = Settings.get_by_key_name("current_version")
if setting is None:
self.ErrMessage = "Failed fetching data"
self.Error = True;
else:
self.CurrentVersion = setting.value

setting = Settings.get_by_key_name("current_site")
if setting is None:
self.ErrMessage = "Failed fetching data"
self.Error = True;
else:
self.DownloadSite = setting.value

setting = Settings.get_by_key_name("current_motd")
if setting is None:
self.ErrMessage = "Failed fetching data"
self.Error = True;
else:
self.MOTD = setting.value


setting = Settings.get_by_key_name("current_display_motd")
if setting is None:
self.ErrMessage = "Failed fetching data"
self.Error = True;
else:
self.DisplayMOTD = setting.value == "true"
Binary file added static/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/bgcode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/bgitem.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/bgmenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/dark_pixel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 148 additions & 0 deletions static/default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*#############################################################
Name: Blackbox
Date: 2006-06-01
Description: A mystic dark lightweight design.
Author: Viktor Persson
URL: http://templates.arcsin.se
Feel free to use and modify but please provide credits.
$Id: default.css 1 2009-09-06 03:46:09Z ek $
#############################################################*/

/* standard elements */
* {
margin: 0;
padding: 0;
}
a {
color: #fff;
text-decoration: none;
}
body {
background: #000 url(/static/bg.png) repeat-x fixed left bottom;
color: #999;
font: normal 0.8em sans-serif,Arial;
margin: 20px 0;
text-align: center;
}
ul {
margin: 12px 0;
}

li {
list-style: url(/static/li.gif);
margin-left: 18px;
}

li:hover {
background: #222;
}

input {
border: 1px solid #666;
background: #444;
font-weight: bold;
color: #aaa;
}

code {
background: url(/static/bgcode.gif);
color: #888;
display: block;
font: normal 1em "Lucida Sans Unicode",serif;
margin-bottom: 12px;
padding: 3px 6px;
white-space: pre;
}

cite {
background: url(/static/quote.gif) no-repeat;
color: #aaa;
display: block;
font: normal 1.1em "Lucida Sans Unicode",serif;
margin-bottom: 12px;
padding-left: 28px;
}


/* main structure */
.main {
background: #000;
border: 3px double #EEE;
border-color: #141414 #202020 #222 #202020;
margin: 20px auto 4px auto;
text-align: left;
width: 600px;
}


/* header */
.gfx {
background: #222 url(/static/dark_pixel.jpg) no-repeat;
height: 240px;
}
.gfx h1 {
color: #aaa;
font: normal 2.6em Tahoma,sans-serif;
padding: 16px 20px;
}


/* menu */
.menu a {
background: #000 url(/static/bgmenu.png) repeat-x;
border-right: 1px solid #222;
border-top: 1px solid #1A1A1A;
color: #aaa;
float: left;
font-size: 1.2em;
padding-top: 4px;
padding-left: 20px;
padding-right: 20px;
height: 36px;
}
.menu a span {
padding-left: 6px;
}
.menu a:hover {
background-position: left bottom;
color: #666;
}
.menu a#last {
border-right: none;
width: 150px;
}


/* content */
.content {
background: #1A1A1A;
border-top: 1px solid #1A1A1A;
clear: both;
}
.content h1 {
color: #aaa;
font: bold 1.1em sans-serif,Arial;
margin: 0 0 4px;
}
.content p {
margin: 0 0 12px;
}
.item {
background: #030303 url(/static/bgitem.gif) repeat-x;
padding: 8px 10px;
}


/* footer */
.footer {
background: #0A0A0A;
color: #666;
padding: 5px;
}
.footer .left, .footer .right {padding: 0 12px;}

/* floats */
.left {float: left;}
.right {float: right;}
.clearer {clear: both;}
Binary file added static/favicon.ico
Binary file not shown.
Binary file added static/li.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/quote.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions svc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# $Id: svc.py 7 2009-09-22 14:20:21Z lkalif $

import wsgiref.handlers
import radupdater
from radupdater import Settings
from radupdater import UpdateInfo
from google.appengine.ext import webapp

class MainHandler(webapp.RequestHandler):
def get(self):
ret = UpdateInfo()
self.response.headers["Content-Type"] = "text/plain"
# self.response.headers["Content-Type"] = "application/json"
self.response.out.write(ret.json())

def main():
app = webapp.WSGIApplication([
(r'/svc/get_latest', MainHandler),
], debug=False)
wsgiref.handlers.CGIHandler().run(app)

if __name__ == '__main__':
main()

Loading

0 comments on commit 0926c01

Please sign in to comment.