Permalink
Browse files

Merge MacOSX code to automatically follow development

Worked to auto-update to 0.4.8-rc1 for me, Alessio Palmero
Aprosio and Francesco Corazza.

I also tested it with: no config file, empty config file,
config file referencing "stable" update channel.
  • Loading branch information...
bassosimone committed Feb 2, 2012
2 parents f38a60f + 07f2b66 commit 01141beba3875b05c2c0354cac6d007a537004c3
Showing with 84 additions and 5 deletions.
  1. +23 −5 neubot/updater/unix.py
  2. +61 −0 neubot/utils_rc.py
View
@@ -101,6 +101,13 @@
else:
import httplib as __lib_http
if __name__ == '__main__':
# PARENT/neubot/updater/unix.py
sys.path.insert(0, os.path.dirname (os.path.dirname(os.path.dirname
(os.path.abspath(__file__)))))
from neubot import utils_rc
# Note: BASEDIR/VERSIONDIR/neubot/updater/unix.py
VERSIONDIR = os.path.dirname(os.path.dirname(os.path.dirname(
os.path.abspath(__file__))))
@@ -109,6 +116,11 @@
# Version number in numeric representation
VERSION = "0.004007999"
# Configuration
CONFIG = {
'channel': 'latest',
}
#
# Common
#
@@ -591,13 +603,13 @@ def __download(address, rpath, tofile=False, https=False, maxbytes=67108864):
else:
os._exit(0)
def __download_version_info(address):
def __download_version_info(address, channel):
'''
Download the latest version number. The version number here
is in numeric representation, i.e. a floating point number with
exactly nine digits after the radix point.
'''
version = __download(address, "/updates/latest")
version = __download(address, "/updates/%s" % channel)
if not version:
raise RuntimeError('Download failed')
version = __printable_only(version)
@@ -642,7 +654,7 @@ def __verify_sig(signature, tarball):
if retval != 0:
raise RuntimeError('Signature does not match')
def __download_and_verify_update(server):
def __download_and_verify_update(server, channel):
'''
If an update is available, download the updated tarball
@@ -655,7 +667,7 @@ def __download_and_verify_update(server):
VERSION)
# Get latest version
nversion = __download_version_info(server)
nversion = __download_version_info(server, channel)
if decimal.Decimal(nversion) <= decimal.Decimal(VERSION):
syslog.syslog(syslog.LOG_INFO, 'No updates available')
return None
@@ -713,7 +725,8 @@ def _download_and_verify_update(server='releases.neubot.org'):
and handles exceptions.
'''
try:
return __download_and_verify_update(server)
channel = CONFIG['channel']
return __download_and_verify_update(server, channel)
except:
why = asyncore.compact_traceback()
syslog.syslog(syslog.LOG_ERR,
@@ -882,6 +895,11 @@ def __main():
# Open the system logger
syslog.openlog('neubot(updater)', logopt, syslog.LOG_DAEMON)
# Read configuration file
if os.path.isfile('/etc/neubot/updater'):
cnf = utils_rc.parse_safe('/etc/neubot/updater')
CONFIG.update(cnf)
# Clear root user environment
__change_user(__lookup_user_info('root'))
View
@@ -0,0 +1,61 @@
# neubot/utils_rc.py
#
# Copyright (c) 2012 Simone Basso <bassosimone@gmail.com>,
# NEXA Center for Internet & Society at Politecnico di Torino
#
# This file is part of Neubot <http://www.neubot.org/>.
#
# Neubot 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, either version 3 of the License, or
# (at your option) any later version.
#
# Neubot 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 Neubot. If not, see <http://www.gnu.org/licenses/>.
#
''' Configuration file utils '''
import shlex
import sys
def parse(path):
''' Parse configuration file '''
conf = {}
filep = open(path, 'rb')
lineno = 0
for line in filep:
lineno += 1
tokens = shlex.split(line, True)
if not tokens:
continue
if len(tokens) != 2:
sys.stderr.write('utils_rc: %s:%d: Invalid line\n' % (
path, lineno))
return {}
name, value = tokens
conf[name] = value
return conf
def parse_safe(path):
''' Parse configuration file (safe) '''
try:
return parse(path)
except (KeyboardInterrupt, SystemExit):
raise
except:
return {}
def main(args):
''' main() function '''
for arg in args[1:]:
print parse(arg)
if __name__ == '__main__':
main(sys.argv)

0 comments on commit 01141be

Please sign in to comment.