Skip to content

Commit

Permalink
Merge pull request #5 from KanoComputing/os-updates
Browse files Browse the repository at this point in the history
Os updates
  • Loading branch information
pazdera committed Apr 2, 2014
2 parents dfb6ad5 + f8c889d commit 141ec43
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 41 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
kano-updater (1.0.1-1) unstable; urgency=low

* Bumping updater to 1.0.1

-- Team Kano <[email protected]> Wed, 07 Mar 2014 21:04:15 +0000

kano-updater (1.0-46) unstable; urgency=low

* Package rebuilt, updated to revision 6c6ffd04.
Expand Down
16 changes: 9 additions & 7 deletions debian/install
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
kano-updater /usr/bin
expand-rootfs /usr/bin
kano-updater usr/bin
expand-rootfs usr/bin

pre_update /usr/share/kano-updater
post_update /usr/share/kano-updater
python_modules /usr/share/kano-updater
pre_update usr/share/kano-updater
post_update usr/share/kano-updater
python_modules usr/share/kano-updater

icon/Updater /usr/share/kano-desktop/extras
icon/kano-updater.png /usr/share/kano-desktop/icons
kano_updater usr/lib/python2.7/dist-packages/

icon/Updater usr/share/kano-desktop/extras
icon/kano-updater.png usr/share/kano-desktop/icons
37 changes: 3 additions & 34 deletions kano-updater
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,7 @@ import os
import sys
import kano.utils as h
from kano.network import is_internet


class OSVersion:
def __init__(self, os=None, codename=None, version=None):
self._os = os
self._codename = codename
self._number = version

def from_version_file(self, vfile_path):
with open(vfile_path, "r") as vfile:
vstr = vfile.read().strip()
try:
self._os, self._codename, self._number = vstr.split("-")
except:
raise Exception("Unknown version string format ({})".format(vstr))

return self

def to_issue(self):
return "{} {} {} \\l".format(self._os, self._codename, self._number)

def to_version_string(self):
return "{}-{}-{}".format(self._os, self._codename, self._number)


def bump_system_version(ver, version_file_path, issue_file_path):
with open(version_file_path, "w") as vfile:
vfile.write(ver.to_version_string() + "\n")

with open(issue_file_path, "w") as ifile:
ifile.write(ver.to_issue() + "\n")

from kano_updater.OSVersion import OSVersion, bump_system_version

def upgrade_debian():
global err_log
Expand Down Expand Up @@ -149,8 +118,8 @@ def get_installed_version(pkg):

issue_file = "/etc/issue"
version_file = "/etc/kanux_version"
old_version = OSVersion().from_version_file(version_file)
new_version = OSVersion("Kanux", "Beta", "1.1")
old_version = OSVersion.from_version_file(version_file)
new_version = OSVersion("Kanux", "Beta", "1.0.1")

err_log_file = '/var/log/kano-updater-log'
python_modules_file = '/usr/share/kano-updater/python_modules'
Expand Down
56 changes: 56 additions & 0 deletions kano_updater/OSVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

# kano-extras Python library
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2

class OSVersion:
@staticmethod
def from_version_string(vstr):
try:
_os, _codename, _number = vstr.split("-")
except:
msg = "Unknown version string format ({})".format(vstr)
raise Exception(msg)

return OSVersion(_os, _codename, _number)

@staticmethod
def from_version_file(vfile_path):
with open(vfile_path, "r") as vfile:
vstr = vfile.read().strip()
return OSVersion.from_version_string(vstr)

def __init__(self, os="Kanux", codename=None, version=None):
self._os = os
self._codename = codename
self._number = version

def to_issue(self):
return "{} {} {} \\l".format(self._os, self._codename, self._number)

def to_version_string(self):
return "{}-{}-{}".format(self._os, self._codename, self._number)

def __str__(self):
return self.to_version_string()

def __eq__(self, other):
return str(self) == str(other)

def __lt__(self, other):
return str(self) < str(other)

def __gt__(self, other):
return str(self) > str(other)

def __cmp__(self, other):
return cmp(str(self), str(other))

def bump_system_version(ver, version_file_path, issue_file_path):
with open(version_file_path, "w") as vfile:
vfile.write(ver.to_version_string() + "\n")

with open(issue_file_path, "w") as ifile:
ifile.write(ver.to_issue() + "\n")
34 changes: 34 additions & 0 deletions kano_updater/Update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

import sys
from kano_updater.OSVersion import OSVersion

class Update(object):
def __init__(self, up_type):
if len(sys.argv) != 3:
msg = 'Two arguments are required (the old and new versions)\n'
sys.stderr.write(msg)
sys.exit(1)

self._type = up_type
print 'Runing the {}-update scripts...'.format(up_type)

self._old = OSVersion.from_version_string(sys.argv[1])
self._new = OSVersion.from_version_string(sys.argv[2])

def get_old(self):
return self._old

def get_new(self):
return self._new

def from_to(self, from_v, to_v):
run = self._old == OSVersion.from_version_string(from_v) and \
self._new == OSVersion.from_version_string(to_v)
if run:
print "Doing {}-update from {} to {}".format(self._type,
from_v, to_v)
return run
26 changes: 26 additions & 0 deletions kano_updater/Utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

# kano-extras Python library
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#
# Utilities for the updater and the pre and post update scripts

from kano.utils import run_print_output_error

def install(pkgs):
if isinstance(pkgs, list):
pkgs = ' '.join(pkgs)

cmd = 'apt-get install -o Dpkg::Options::="--force-confdef" ' + \
'-o Dpkg::Options::="--force-confold" -y --force-yes ' + str(pkgs)
print cmd
run_print_output_error(cmd)

def remove(pkgs):
pass #TODO


def purge(pkgs):
pass #TODO
9 changes: 9 additions & 0 deletions kano_updater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

# kano-extras Python library
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2

__author__ = 'Kano Computing Ltd.'
__email__ = '[email protected]'
9 changes: 9 additions & 0 deletions post_update
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env python
# post_update
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

from kano_updater.Utils import install, remove, purge
from kano_updater.Update import Update

update = Update("post")

if update.from_to('Kanux-Beta-1.0', 'Kanux-Beta-1.0.1'):
install('kano-extras')
9 changes: 9 additions & 0 deletions pre_update
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env python
# pre_update
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

from kano_updater.Utils import install, remove, purge
from kano_updater.Update import Update

update = Update("pre")

if update.from_to('Kanux-Beta-1.0', 'Kanux-Beta-1.0.1'):
pass

0 comments on commit 141ec43

Please sign in to comment.