~ubuntu-branches/ubuntu/natty/jhbuild/natty

« back to all changes in this revision

Viewing changes to scripts/hg-update.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Loic Minier, Emilio Pozuelo Monfort
  • Date: 2009-11-09 20:28:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109202848-m9ec7dmzptqtchtj
Tags: 2.28.0-1
[ Loic Minier ]
* Cleanups.
* Ship scripts.
* Don't set GNOME_MODULE as it equals the name of the source package.

[ Emilio Pozuelo Monfort ]
* New upstream release. Closes: #524504.
  - Use 'git rev-parse' rather than 'git-rev-parse'. Closes: #544642.
* Ship install-check. Closes: #441008.
* Uploaders list regenerated. Closes: #523542, #554071.
* debian/control.in,
  debian/rules:
  - Stop shipping a copy of subprocess.py. Require python >= 2.4.
  - Switch to python-support.
* debian/control.in:
  - Bump Standards-Version to 3.8.3, no changes needed.
  - Build depend on intltool >= 0.35.0.
  - Build depend on pkg-config, gnome-doc-utils and rarian-compat to build
    the documentation.
  - Make jhbuild arch any since install-check is a binary. Depend on
    ${shlibs:Depends}.
  - Recommend, and not suggest, git-core. Also recommend mercurial.
* debian/watch:
  - Added.
* debian/patches/01_import_from_pkgdatadir.patch:
  - Added, import jhbuild from pkgdatadir if everything else fails.
    This way we can ship the jhbuild private modules in /usr/sharejhbuild.
* debian/jhbuild.docs:
  - Removed, the necessary docs are now installed by the upstream Makefile.
* debian/rules:
  - Include autotools.mk and gnome.mk.
  - Remove all the manual build process, autotools.mk does everything now.
  - Install the jhbuild modules in /usr/share/jhbuild.
* debian/install:
  - Install the modulesets and patches from here since the upstream build
    system doesn't install them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
#
 
3
# hg-update - pull and update a mercurial repository
 
4
#
 
5
# Copyright (C) 2007  Marco Barisione <marco@barisione.org>
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 
 
21
import os
 
22
import sys
 
23
import re
 
24
 
 
25
try:
 
26
    from subprocess import Popen, call, PIPE, STDOUT
 
27
except ImportError: # Python < 2.4 lacks subprocess module
 
28
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
 
29
    from jhbuild.cut_n_paste import subprocess
 
30
    sys.modules['subprocess'] = subprocess
 
31
    from subprocess import Popen, call, PIPE, STDOUT
 
32
 
 
33
def get_parent():
 
34
    hg = Popen(['hg', 'parents', '--template', '{rev}'], stdout=PIPE)
 
35
    try:
 
36
        return hg.stdout.read().split()[0]
 
37
    except IndexError:
 
38
        # handle parentless revisions
 
39
        return ''
 
40
 
 
41
def pull():
 
42
    ret = call(['hg', 'pull'])
 
43
    return ret == 0
 
44
 
 
45
def update():
 
46
    env = dict(os.environ)
 
47
    env['HGMERGE'] = '/bin/false'
 
48
    env['LANG'] = 'C'
 
49
    hg = Popen(['hg', 'update', '--noninteractive'], stdout=PIPE,
 
50
               stderr=STDOUT, env=env)
 
51
    out = hg.communicate()[0]
 
52
    if hg.returncode != 0:
 
53
        # Use CVS-like format for conflicts.
 
54
        out = re.sub('merging (.*) failed!', r'C \1', out)
 
55
        index = out.find('You can redo the full merge using:')
 
56
        # Remove the instructions to redo the full merge as we are
 
57
        # going to revert the update.
 
58
        if index != -1:
 
59
            out = out[:index]
 
60
    print out
 
61
    return hg.returncode == 0
 
62
 
 
63
def undo_update(parent):
 
64
    print 'Update failed, updating to parent revision'
 
65
    env = dict(os.environ)
 
66
    env['HGMERGE'] = 'false'
 
67
    hg = call(['hg', 'update', '--noninteractive', '-q', parent], env=env)
 
68
 
 
69
def pull_and_update():
 
70
    parent = get_parent()
 
71
    if not pull():
 
72
        return False
 
73
    if update():
 
74
        return True
 
75
    else:
 
76
        undo_update(parent)
 
77
        return False
 
78
 
 
79
if __name__ == '__main__':
 
80
    ret = False
 
81
    try:
 
82
        ret = pull_and_update()
 
83
    except OSError, e:
 
84
        print '%s: %s' % (sys.argv[0], e)
 
85
 
 
86
    if ret:
 
87
        exit_code = 0
 
88
    else:
 
89
        exit_code = 1
 
90
    sys.exit(exit_code)
 
91