Merge lp:~therp-nl/openupgrade-server/7.0_migrate_script into lp:openupgrade-server

Proposed by Holger Brunn (Therp)
Status: Merged
Merged at revision: 4613
Proposed branch: lp:~therp-nl/openupgrade-server/7.0_migrate_script
Merge into: lp:openupgrade-server
Diff against target: 97 lines (+33/-19)
1 file modified
scripts/migrate.py (+33/-19)
To merge this branch: bzr merge lp:~therp-nl/openupgrade-server/7.0_migrate_script
Reviewer Review Type Date Requested Status
Stefan Rijnhart (Opener) Approve
Review via email: mp+162607@code.launchpad.net

Commit message

[ADD] migration call for 7.0
[IMP] use lightweight checkouts instead of branches, that saves a lot of
time and space
[IMP] always use versioned lp urls
[IMP] make migrate script executable

Description of the change

updated migrate.py

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Good! Could you please take out the reference to banking-addons, which I believe should be part of your local configuration.

review: Needs Fixing
4613. By Holger Brunn (Therp)

[IMP] remove banking addons from default update code
[IMP] give banking addons as an example on how to add update code
[FIX] typos in help texts

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks, I took this as an opportunity to elaborate on the help text for -A

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Testing your script as I need to upgrade a database. I downloaded the script separately as follows

bzr cat -d lp:~therp-nl/openupgrade-server/7.0_migrate_script scripts/migrate.py > migrate.py
./migrate.py -D diflbv -C ../../diflbv.cfg -R 6.1 -A add.py

Contents of add.py:

{'6.1': {'addons': {'banking': 'lp:banking-addons/6.1'}}}

This gives the following exception:

  File "./migrate.py", line 115, in <module>
    merge_migrations=merge_migrations_mod.migrations
AttributeError: 'module' object has no attribute 'migrations'

Line 113 attempts to load a python module called 'merge_migrations_mod' which I do not have because I downloaded the script as a standalone file but which is not present in the bzr branch either. Did you forget to push a module at some point?

review: Needs Information
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

your add.py needs to declare a global variable named 'migrations'.

So make a
migrations = {'6.1': {'addons': {'banking': 'lp:banking-addons/6.1'}}}
of it and it should work fine.

Or pass
-A "{'6.1': {'addons': {'banking': 'lp:banking-addons/6.1'}}}"

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

btw: the first parameter of imp.load_source is an arbitrary name how you want to call the module you import

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks for the info! It works when I change the contents of add.py accordingly.

Small glitch that needs to be repaired in the 6.1 definitions:

--- scripts/migrate.py 2013-05-07 06:46:24 +0000
+++ scripts/migrate.py 2013-05-09 08:32:59 +0000
@@ -34,7 +34,7 @@
           'web': {'url': 'lp:openerp-web/6.1', 'addons_dir': 'addons'},
         },
       'server': {
- 'url': 'lp:openupgrade-server',
+ 'url': 'lp:openupgrade-server/6.1',
           'addons_dir': os.path.join('openerp','addons'),
           'root_dir': os.path.join(''),
           'cmd': 'openerp-server --update=all --database=%(db)s '+

Using lightweight checkouts makes the script much faster! That is great for most uses. However, I cannot merge in any pending improvements anymore as a user without write access to the Launchpad series branch:

bzr merge lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence
bzr: ERROR: Cannot lock LockDir(http://bazaar.launchpad.net/~openupgrade-committers/openupgrade-addons/6.1/.bzr/branch/lock): Transport operation not possible: http does not support mkdir()

I can then replace the lightweight checkout by a branch and proceed. The migrate script will run, but if I reuse the migration directory later on, the branch will not get updated with the latest upstream revisions because the script performs an 'update', not a 'pull'.

My suggestion would be as follows:
- Optionally allow to get the code using a branch instead of a lightweight checkout
- When updating the code, use either pull or update depending on whether you are dealing with a branch or a checkout

What do you think?

review: Needs Information
4614. By Holger Brunn (Therp)

[FIX] also use correct version for openupgrade-server 6.1

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks for the pointer on the server url!

Concerning the pull/update issue: I think adding another commandline switch serves mostly to confuse a user. If you want to do development in this directories, you can say
bzr reconfigure --branch #yes, that's necessary because making it a tree directly crashes
bzr reconfigure --tree
[hackhackhack]
bzr commit
bzr push [your location]
bzr bind [original location]
So I'd rather leave it to the developer to do that.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

OK, we will leave it at that then. I can pull upstream revisions manually if I reuse an existing branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/migrate.py' (properties changed: -x to +x)
2--- scripts/migrate.py 2012-11-24 22:22:00 +0000
3+++ scripts/migrate.py 2013-05-09 13:52:27 +0000
4@@ -15,14 +15,26 @@
5 import bzrlib.info
6
7 migrations={
8+ '7.0': {
9+ 'addons': {
10+ 'addons': 'lp:openupgrade-addons/7.0',
11+ 'web': {'url': 'lp:openerp-web/7.0', 'addons_dir': 'addons'},
12+ },
13+ 'server': {
14+ 'url': 'lp:openupgrade-server/7.0',
15+ 'addons_dir': os.path.join('openerp','addons'),
16+ 'root_dir': os.path.join(''),
17+ 'cmd': 'openerp-server --update=all --database=%(db)s '+
18+ '--config=%(config)s --stop-after-init --no-xmlrpc --no-netrpc',
19+ },
20+ },
21 '6.1': {
22 'addons': {
23- 'addons': 'lp:openupgrade-addons',
24- 'banking': 'lp:banking-addons',
25+ 'addons': 'lp:openupgrade-addons/6.1',
26 'web': {'url': 'lp:openerp-web/6.1', 'addons_dir': 'addons'},
27 },
28 'server': {
29- 'url': 'lp:openupgrade-server',
30+ 'url': 'lp:openupgrade-server/6.1',
31 'addons_dir': os.path.join('openerp','addons'),
32 'root_dir': os.path.join(''),
33 'cmd': 'openerp-server --update=all --database=%(db)s '+
34@@ -32,7 +44,6 @@
35 '6.0': {
36 'addons': {
37 'addons': 'lp:openupgrade-addons/6.0',
38- 'banking': 'lp:banking-addons/6.0',
39 },
40 'server': {
41 'url': 'lp:openupgrade-server/6.0',
42@@ -62,12 +73,15 @@
43 default='/var/tmp/openupgrade')
44 parser.add_option("-R", "--run-migrations", action="store", type="string",
45 dest="migrations",
46- help="comma separated list of migrations to run\n\n"+
47+ help="comma separated list of migrations to run, ie. \""+
48 ','.join(sorted([a for a in migrations]))+
49- "\n(required)")
50+ "\" (required)")
51 parser.add_option("-A", "--add", action="store", type="string", dest="add",
52- help="load a python module that declares on dict 'migrations' which is"+
53- " merged with the one of this script (see the source for details)")
54+ help="load a python module that declares a dict 'migrations' which is "+
55+ "merged with the one of this script (see the source for details). "
56+ "You also can pass a string that evaluates to a dict. For the banking "
57+ "addons, pass "
58+ "\"{'6.1': {'addons': {'banking': 'lp:banking-addons/6.1'}}}\"")
59 parser.add_option("-I", "--inplace", action="store_true", dest="inplace",
60 help="don't copy database before attempting upgrade (dangerous)")
61 (options, args) = parser.parse_args()
62@@ -148,13 +162,13 @@
63 name))
64 print 'updating %s rev%s' %(os.path.join(version,name),
65 cmd_revno.outf.getvalue().strip())
66- cmd_pull=bzrlib.builtins.cmd_pull()
67- cmd_pull.outf=StringIO.StringIO()
68- cmd_pull.outf.encoding='utf8'
69- cmd_pull.run(directory=os.path.join(options.branch_dir,version,
70- name), overwrite=True)
71- if hasattr(cmd_pull, '_operation'):
72- cmd_pull.cleanup_now()
73+ cmd_update=bzrlib.builtins.cmd_update()
74+ cmd_update.outf=StringIO.StringIO()
75+ cmd_update.outf.encoding='utf8'
76+ cmd_update.run(dir=os.path.join(options.branch_dir,version,
77+ name))
78+ if hasattr(cmd_update, '_operation'):
79+ cmd_update.cleanup_now()
80 print 'now at rev'+cmd_revno.outf.getvalue().strip()
81 else:
82 if link:
83@@ -163,10 +177,10 @@
84 os.symlink(url, os.path.join(options.branch_dir,version,name))
85 else:
86 print 'getting '+url
87- cmd_branch=bzrlib.builtins.cmd_branch()
88- cmd_branch.outf=StringIO.StringIO()
89- cmd_branch.run(url, os.path.join(options.branch_dir,version,
90- name))
91+ cmd_checkout=bzrlib.builtins.cmd_checkout()
92+ cmd_checkout.outf=StringIO.StringIO()
93+ cmd_checkout.run(url, os.path.join(options.branch_dir,version,
94+ name), lightweight=True)
95
96 if not options.inplace:
97 print('copying database %(db_name)s to %(db)s...' % {'db_name': db_name,

Subscribers

People subscribed via source and target branches