~nskaggs/juju-release-tools/generate-release-notes

« back to all changes in this revision

Viewing changes to apply_patches.py

  • Committer: Martin Packman
  • Date: 2016-07-21 15:30:35 UTC
  • mto: This revision was merged to the branch mainline in revision 322.
  • Revision ID: martin.packman@canonical.com-20160721153035-ai13acbt76tzqkfa
Switch to using stderr for apply_patches output

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
"""Script for applying a directory of patches to a source tree."""
3
3
 
 
4
from __future__ import print_function
 
5
 
4
6
from argparse import ArgumentParser
5
7
import gettext
6
8
import os
7
9
import subprocess
8
10
import sys
9
11
 
10
 
import utils
11
 
 
12
12
 
13
13
def apply_patch(patch_file, base_dir, dry_run=False, verbose=False):
14
14
    """Run external patch command to apply given patch_file to base_dir."""
46
46
    if not os.path.isdir(args.srctree):
47
47
        parser.error("Source tree '{}' not a directory".format(args.srctree))
48
48
    patch_count = len(patches)
49
 
    utils.print_now(gettext.ngettext(
 
49
    print(gettext.ngettext(
50
50
        u"Applying {} patch", u"Applying {} patches", patch_count).format(
51
 
        patch_count))
 
51
        patch_count), file=sys.stderr)
52
52
    for patch in patches:
53
53
        patch_path = os.path.join(args.patchdir, patch)
54
54
        if apply_patch(patch_path, args.srctree, args.dry_run, args.verbose):
55
 
            utils.print_now(gettext.gettext(
56
 
                u"Failed to apply patch '{}'").format(patch))
 
55
            print(gettext.gettext(
 
56
                u"Failed to apply patch '{}'").format(patch), file=sys.stderr)
57
57
            return 1
58
 
        utils.print_now(gettext.gettext(u"Applied patch '{}'").format(patch))
 
58
        print(gettext.gettext(
 
59
            u"Applied patch '{}'").format(patch), file=sys.stderr)
59
60
    return 0
60
61
 
61
62