~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/tools/upgrade.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: config.py 996 2005-07-22 10:40:10Z nicoe $
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import tarfile
 
31
import re
 
32
import urllib2
 
33
import os
 
34
import shutil
 
35
import tools
 
36
 
 
37
 
 
38
# remove an existing version of modules if it exist
 
39
def remove(name):
 
40
        adp = tools.config['addons_path']
 
41
        addons = os.listdir(adp)
 
42
        if name in addons:
 
43
                try:
 
44
                        shutil.rmtree(os.path.join(adp, name))
 
45
                except:
 
46
                        print "Unable to remove module %s !" % name
 
47
 
 
48
def install(name, url):
 
49
        tar = tarfile.open(mode="r|gz", fileobj=urllib2.urlopen(url))
 
50
        for tarinfo in tar:
 
51
                tar.extract(tarinfo, tools.config['addons_path'])
 
52
 
 
53
def upgrade():
 
54
        import pooler
 
55
        cr = pooler.db.cursor()
 
56
 
 
57
        toinit = []
 
58
        toupdate = []
 
59
 
 
60
#       print 'Check for correct rights (create and unlink on addons)...'
 
61
        # todo: touch addons/test.txt
 
62
        # todo: rm addons/test.txt
 
63
 
 
64
        print 'Check for modules to remove...'
 
65
        cr.execute('select id,name,url from ir_module_module where state=%s', ('to remove',))
 
66
        for module_id,name,url in cr.fetchall():
 
67
                print '\tremoving module %s' % name
 
68
                remove(name)
 
69
                cr.execute('update ir_module_module set state=%s where id=%d', ('uninstalled', module_id))
 
70
                cr.commit()
 
71
 
 
72
        print 'Check for modules to upgrade...'
 
73
        cr.execute('select id,name,url from ir_module_module where state=%s', ('to upgrade',))
 
74
        for module_id,name,url in cr.fetchall():
 
75
                print '\tupgrading module %s' % name
 
76
                remove(name)
 
77
                install(name, url)
 
78
                cr.execute('update ir_module_module set state=%s where id=%d', ('installed', module_id))
 
79
                cr.commit()
 
80
                toupdate.append(name)
 
81
 
 
82
        print 'Check for modules to install...'
 
83
        cr.execute('select id,name,url from ir_module_module where state=%s', ('to install',))
 
84
        for module_id,name,url in cr.fetchall():
 
85
                print '\tinstalling module %s' % name
 
86
                install(name, url)
 
87
                cr.execute('update ir_module_module set state=%s where id=%d', ('installed', module_id))
 
88
                cr.commit()
 
89
                toinit.append(name)
 
90
 
 
91
        print 'Initializing all datas...'
 
92
 
 
93
        cr.commit()
 
94
        cr.close()
 
95
        return (toinit, toupdate)
 
96