From dd2cd26d4574783f67523985cb2cc41b37296a2a Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Tue, 1 Apr 2014 17:07:15 +0100 Subject: [PATCH 1/9] refactor: Moving parts of kano-updater to dist --- debian/install | 16 +++++++++------- kano-updater | 33 +-------------------------------- kano_updater/OSVersion.py | 36 ++++++++++++++++++++++++++++++++++++ kano_updater/__init__.py | 9 +++++++++ 4 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 kano_updater/OSVersion.py create mode 100644 kano_updater/__init__.py diff --git a/debian/install b/debian/install index 87762ae2..d503bec5 100644 --- a/debian/install +++ b/debian/install @@ -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 diff --git a/kano-updater b/kano-updater index f2957f88..a41a6704 100755 --- a/kano-updater +++ b/kano-updater @@ -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 diff --git a/kano_updater/OSVersion.py b/kano_updater/OSVersion.py new file mode 100644 index 00000000..511a3aae --- /dev/null +++ b/kano_updater/OSVersion.py @@ -0,0 +1,36 @@ +#!/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: + 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: + msg = "Unknown version string format ({})".format(vstr) + raise Exception() + + 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") diff --git a/kano_updater/__init__.py b/kano_updater/__init__.py new file mode 100644 index 00000000..d161aa38 --- /dev/null +++ b/kano_updater/__init__.py @@ -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__ = 'dev@kano.me' From cd7f263e146ca3cb65d903f8aad95c8bc2278081 Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Tue, 1 Apr 2014 18:06:18 +0100 Subject: [PATCH 2/9] osversion: More refactoring --- kano-updater | 2 +- kano_updater/OSVersion.py | 42 +++++++++++++++++++++++++++++---------- post_update | 8 ++++++++ pre_update | 7 +++++++ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/kano-updater b/kano-updater index a41a6704..3bc6e6a6 100755 --- a/kano-updater +++ b/kano-updater @@ -118,7 +118,7 @@ def get_installed_version(pkg): issue_file = "/etc/issue" version_file = "/etc/kanux_version" -old_version = OSVersion().from_version_file(version_file) +old_version = OSVersion.from_version_file(version_file) new_version = OSVersion("Kanux", "Beta", "1.1") err_log_file = '/var/log/kano-updater-log' diff --git a/kano_updater/OSVersion.py b/kano_updater/OSVersion.py index 511a3aae..eb2d150f 100644 --- a/kano_updater/OSVersion.py +++ b/kano_updater/OSVersion.py @@ -6,28 +6,48 @@ # 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=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: - msg = "Unknown version string format ({})".format(vstr) - raise Exception() - - 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 __str__(self): + return 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") diff --git a/post_update b/post_update index cb7d0dfd..af00e92a 100755 --- a/post_update +++ b/post_update @@ -1,5 +1,13 @@ +#!/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 * + +old_ver = OSVersion.from_version_string(sys.argv[1]) +new_ver = OSVersion.from_version_string(sys.argv[2]) + + diff --git a/pre_update b/pre_update index 8aa31614..13d4be58 100755 --- a/pre_update +++ b/pre_update @@ -1,5 +1,12 @@ +#!/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.OSVersion import OSVersion +from kano_updater.Utils import * + +old_ver = OSVersion.from_version_string(sys.argv[1]) +new_ver = OSVersion.from_version_string(sys.argv[2]) From a3e6ee64e42a118a74b986a3d658494954e9a92f Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Tue, 1 Apr 2014 18:08:12 +0100 Subject: [PATCH 3/9] lib: Adding the Utils module --- kano_updater/Utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 kano_updater/Utils.py diff --git a/kano_updater/Utils.py b/kano_updater/Utils.py new file mode 100644 index 00000000..f686a8df --- /dev/null +++ b/kano_updater/Utils.py @@ -0,0 +1,8 @@ +#!/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 3fad33ac05f8c7b0ddec51ed6df8f6ceaaa58ec8 Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Tue, 1 Apr 2014 18:29:53 +0100 Subject: [PATCH 4/9] scripts: Added the Update class --- kano_updater/OSVersion.py | 2 +- kano_updater/Utils.py | 37 +++++++++++++++++++++++++++++++++++++ post_update | 9 +++++---- pre_update | 10 ++++++---- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/kano_updater/OSVersion.py b/kano_updater/OSVersion.py index eb2d150f..54506d30 100644 --- a/kano_updater/OSVersion.py +++ b/kano_updater/OSVersion.py @@ -22,7 +22,7 @@ def from_version_file(vfile_path): vstr = vfile.read().strip() return OSVersion.from_version_string(vstr) - def __init__(self, os=None, codename=None, version=None): + def __init__(self, os="Kanux", codename=None, version=None): self._os = os self._codename = codename self._number = version diff --git a/kano_updater/Utils.py b/kano_updater/Utils.py index f686a8df..a895f933 100644 --- a/kano_updater/Utils.py +++ b/kano_updater/Utils.py @@ -6,3 +6,40 @@ # 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_updater.OSVersion import OSVersion + +class Update(object): + def __init__(self, old_ver, new_ver): + self._old = OSVersion.from_version_string(old_ver) + self._new = OSVersion.from_version_string(new_ver) + + def get_old(self): + return self._old + + def get_new(self): + return self._new + + def from(self, v): + return From(self, v) + + def to(self, v): + return To(self, v) + +class From(object): + def __init__(self, up, from_v): + self._up = up + self._from = OSVersion.from_version_string(from_v) + + def to(self, v): + return self._up.get_old() == self._from and \ + self._up.get_new() == OSVersion.from_version_string(v) + +class To(object): + def __init__(self, up, to_v): + self._up = up + self._to = OSVersion.from_version_string(to_v) + + def from(self, v): + return self._up.get_new() == self._to and \ + self._up.get_old() == OSVersion.from_version_string(v) diff --git a/post_update b/post_update index af00e92a..3ab47061 100755 --- a/post_update +++ b/post_update @@ -5,9 +5,10 @@ # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # -from kano_updater.Utils import * - -old_ver = OSVersion.from_version_string(sys.argv[1]) -new_ver = OSVersion.from_version_string(sys.argv[2]) +import sys +from kano_updater.Utils import Update +update = Update(sys.argv[1], sys.argv[2]) +if update.from('Kanux-Beta-1.0').to('Kanux-Beta-1.0.1'): + pass diff --git a/pre_update b/pre_update index 13d4be58..fec45916 100755 --- a/pre_update +++ b/pre_update @@ -5,8 +5,10 @@ # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # -from kano_updater.OSVersion import OSVersion -from kano_updater.Utils import * +import sys +from kano_updater.Utils import Update -old_ver = OSVersion.from_version_string(sys.argv[1]) -new_ver = OSVersion.from_version_string(sys.argv[2]) +update = Update(sys.argv[1], sys.argv[2]) + +if update.from('Kanux-Beta-1.0').to('Kanux-Beta-1.0.1'): + pass From ec28e966a460d2f0b5da584f21c352d270fcaf09 Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Tue, 1 Apr 2014 18:33:47 +0100 Subject: [PATCH 5/9] scripts: Moving Update to a separate file --- kano_updater/Utils.py | 40 ++++++---------------------------------- post_update | 3 ++- pre_update | 3 ++- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/kano_updater/Utils.py b/kano_updater/Utils.py index a895f933..de11cf28 100644 --- a/kano_updater/Utils.py +++ b/kano_updater/Utils.py @@ -7,39 +7,11 @@ # # Utilities for the updater and the pre and post update scripts -from kano_updater.OSVersion import OSVersion +def install(pkgs): + pass -class Update(object): - def __init__(self, old_ver, new_ver): - self._old = OSVersion.from_version_string(old_ver) - self._new = OSVersion.from_version_string(new_ver) +def remove(pkgs): + pass - def get_old(self): - return self._old - - def get_new(self): - return self._new - - def from(self, v): - return From(self, v) - - def to(self, v): - return To(self, v) - -class From(object): - def __init__(self, up, from_v): - self._up = up - self._from = OSVersion.from_version_string(from_v) - - def to(self, v): - return self._up.get_old() == self._from and \ - self._up.get_new() == OSVersion.from_version_string(v) - -class To(object): - def __init__(self, up, to_v): - self._up = up - self._to = OSVersion.from_version_string(to_v) - - def from(self, v): - return self._up.get_new() == self._to and \ - self._up.get_old() == OSVersion.from_version_string(v) +def purge(pkgs): + pass diff --git a/post_update b/post_update index 3ab47061..0343a054 100755 --- a/post_update +++ b/post_update @@ -6,7 +6,8 @@ # import sys -from kano_updater.Utils import Update +from kano_updater.Utils import install, remove, purge +from kano_updater.Update import Update update = Update(sys.argv[1], sys.argv[2]) diff --git a/pre_update b/pre_update index fec45916..85398ce2 100755 --- a/pre_update +++ b/pre_update @@ -6,7 +6,8 @@ # import sys -from kano_updater.Utils import Update +from kano_updater.Utils import install, remove, purge +from kano_updater.Update import Update update = Update(sys.argv[1], sys.argv[2]) From 7d9c104d21ffe62e92afc804ce7b13bd9b981719 Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Wed, 2 Apr 2014 10:29:47 +0100 Subject: [PATCH 6/9] scripts: Finishing update scripts --- kano_updater/OSVersion.py | 2 +- kano_updater/Update.py | 34 ++++++++++++++++++++++++++++++++++ post_update | 5 ++--- pre_update | 5 ++--- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 kano_updater/Update.py diff --git a/kano_updater/OSVersion.py b/kano_updater/OSVersion.py index 54506d30..a1c3c4b8 100644 --- a/kano_updater/OSVersion.py +++ b/kano_updater/OSVersion.py @@ -34,7 +34,7 @@ def to_version_string(self): return "{}-{}-{}".format(self._os, self._codename, self._number) def __str__(self): - return to_version_string() + return self.to_version_string() def __eq__(self, other): return str(self) == str(other) diff --git a/kano_updater/Update.py b/kano_updater/Update.py new file mode 100644 index 00000000..8c5ff798 --- /dev/null +++ b/kano_updater/Update.py @@ -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 diff --git a/post_update b/post_update index 0343a054..002d792d 100755 --- a/post_update +++ b/post_update @@ -5,11 +5,10 @@ # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # -import sys from kano_updater.Utils import install, remove, purge from kano_updater.Update import Update -update = Update(sys.argv[1], sys.argv[2]) +update = Update("post") -if update.from('Kanux-Beta-1.0').to('Kanux-Beta-1.0.1'): +if update.from_to('Kanux-Beta-1.0', 'Kanux-Beta-1.0.1'): pass diff --git a/pre_update b/pre_update index 85398ce2..dd45e40c 100755 --- a/pre_update +++ b/pre_update @@ -5,11 +5,10 @@ # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # -import sys from kano_updater.Utils import install, remove, purge from kano_updater.Update import Update -update = Update(sys.argv[1], sys.argv[2]) +update = Update("pre") -if update.from('Kanux-Beta-1.0').to('Kanux-Beta-1.0.1'): +if update.from_to('Kanux-Beta-1.0', 'Kanux-Beta-1.0.1'): pass From 65a62c118c8cc25686e13f0874c312ac11de661d Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Wed, 2 Apr 2014 11:55:50 +0100 Subject: [PATCH 7/9] version: Bumping to 1.0.1 --- debian/changelog | 6 ++++++ kano-updater | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index eba4efe3..ed7b818a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +kano-updater (1.0.1-1) unstable; urgency=low + + * Bumping updater to 1.0.1 + + -- Team Kano Wed, 07 Mar 2014 21:04:15 +0000 + kano-updater (1.0-46) unstable; urgency=low * Package rebuilt, updated to revision 6c6ffd04. diff --git a/kano-updater b/kano-updater index 3bc6e6a6..4f5ab9ed 100755 --- a/kano-updater +++ b/kano-updater @@ -119,7 +119,7 @@ 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") +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' From bc89de241ebcd5aaf192dcee990579f30ca63acd Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Wed, 2 Apr 2014 12:36:06 +0100 Subject: [PATCH 8/9] Implementing post-update for 1.0.1 --- kano_updater/Utils.py | 13 ++++++++++--- post_update | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/kano_updater/Utils.py b/kano_updater/Utils.py index de11cf28..c2f0542e 100644 --- a/kano_updater/Utils.py +++ b/kano_updater/Utils.py @@ -7,11 +7,18 @@ # # Utilities for the updater and the pre and post update scripts +from kano.utils import run_cmd + def install(pkgs): - pass + cmd = 'apt-get install -o Dpkg::Options::="--force-confdef" ' + + '-o Dpkg::Options::="--force-confold" -y --force-yes ' + + ' '.join(pkgs) + run_cmd(cmd) + def remove(pkgs): - pass + pass #TODO + def purge(pkgs): - pass + pass #TODO diff --git a/post_update b/post_update index 002d792d..0ba74b91 100755 --- a/post_update +++ b/post_update @@ -11,4 +11,4 @@ from kano_updater.Update import Update update = Update("post") if update.from_to('Kanux-Beta-1.0', 'Kanux-Beta-1.0.1'): - pass + install('kano-extras') From f8c889dde7f01d246b57b1b1740c4b888f707839 Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Wed, 2 Apr 2014 15:19:16 +0100 Subject: [PATCH 9/9] utils: Wrong syntax fix --- kano_updater/Utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kano_updater/Utils.py b/kano_updater/Utils.py index c2f0542e..d085c54c 100644 --- a/kano_updater/Utils.py +++ b/kano_updater/Utils.py @@ -7,14 +7,16 @@ # # Utilities for the updater and the pre and post update scripts -from kano.utils import run_cmd +from kano.utils import run_print_output_error def install(pkgs): - cmd = 'apt-get install -o Dpkg::Options::="--force-confdef" ' + - '-o Dpkg::Options::="--force-confold" -y --force-yes ' + - ' '.join(pkgs) - run_cmd(cmd) + 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