~jelmer/bzr-builddeb/auto-apply-quilt

« back to all changes in this revision

Viewing changes to cmds.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-02 17:52:01 UTC
  • mfrom: (675.1.2 defer-imports)
  • Revision ID: jelmer@samba.org-20120102175201-ae60glvwpp0sctti
Merge deferring of imports in cmds.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
22
#
23
23
 
24
 
import commands
25
24
import os
26
25
import shutil
27
 
import subprocess
28
26
import tempfile
29
 
import urlparse
30
 
 
31
 
try:
32
 
    from debian.changelog import Version
33
 
except ImportError:
34
 
    # Prior to 0.1.15 the debian module was called debian_bundle
35
 
    from debian_bundle.changelog import Version
36
27
 
37
28
from bzrlib import (
38
29
    urlutils,
61
52
    BUILD_TYPE_NATIVE,
62
53
    BUILD_TYPE_SPLIT,
63
54
    )
64
 
from bzrlib.plugins.builddeb.errors import (
65
 
    BuildFailedError,
66
 
    DchError,
67
 
    MissingChangelogError,
68
 
    NoPreviousUpload,
69
 
    PackageVersionNotPresent,
70
 
    StrictBuildFailed,
71
 
    )
72
 
from bzrlib.plugins.builddeb.hooks import run_hook
73
55
from bzrlib.plugins.builddeb.util import (
74
 
    FORMAT_3_0_QUILT,
75
 
    FORMAT_3_0_NATIVE,
76
 
    component_from_orig_tarball,
77
56
    debuild_config,
78
 
    dget_changes,
79
 
    find_changelog,
80
 
    find_last_distribution,
81
 
    find_previous_upload,
82
 
    get_source_format,
83
 
    guess_build_type,
84
 
    lookup_distribution,
85
 
    md5sum_filename,
86
 
    open_file,
87
 
    open_file_via_transport,
88
 
    tarball_name,
89
 
    tree_contains_upstream_source,
90
57
    )
91
58
 
92
59
dont_purge_opt = Option('dont-purge',
189
156
        result_compat_opt, package_merge_opt]
190
157
 
191
158
    def _get_tree_and_branch(self, location):
 
159
        import urlparse
192
160
        if location is None:
193
161
            location = "."
194
162
        is_local = urlparse.urlsplit(location)[0] in ('', 'file')
298
266
            quick=False, reuse=False, native=None,
299
267
            source=False, revision=None, result=None, package_merge=None,
300
268
            strict=False):
 
269
        import commands
301
270
        from bzrlib.plugins.builddeb.source_distiller import (
302
271
                FullSourceDistiller,
303
272
                MergeModeDistiller,
304
273
                NativeSourceDistiller,
305
274
                )
306
275
        from bzrlib.plugins.builddeb.builder import DebBuild
 
276
        from bzrlib.plugins.builddeb.errors import (
 
277
            NoPreviousUpload,
 
278
            StrictBuildFailed
 
279
            )
 
280
        from bzrlib.plugins.builddeb.hooks import run_hook
307
281
        from bzrlib.plugins.builddeb.upstream.branch import (
308
282
            LazyUpstreamBranchSource,
309
283
            )
317
291
        from bzrlib.plugins.builddeb.upstream.pristinetar import (
318
292
            PristineTarSource,
319
293
            )
 
294
        from bzrlib.plugins.builddeb.util import (
 
295
            dget_changes,
 
296
            find_changelog,
 
297
            find_previous_upload,
 
298
            guess_build_type,
 
299
            tree_contains_upstream_source,
 
300
            )
320
301
 
321
302
        if result is not None:
322
303
            warning(gettext("--result is deprecated, use --result-dir instead"))
476
457
        from bzrlib.plugins.builddeb.upstream.pristinetar import (
477
458
            PristineTarSource,
478
459
            )
 
460
        from bzrlib.plugins.builddeb.util import (
 
461
            find_changelog,
 
462
            )
479
463
        tree = WorkingTree.open_containing(directory)[0]
480
464
        config = debuild_config(tree, tree)
481
465
 
582
566
            changelog):
583
567
        from bzrlib.plugins.builddeb.merge_upstream import (
584
568
            changelog_add_new_version)
 
569
        from bzrlib.plugins.builddeb.errors import (
 
570
            DchError,
 
571
            )
585
572
        try:
586
573
            changelog_add_new_version(tree, version, distribution_name,
587
574
                changelog, package)
598
585
            DistributionBranch,
599
586
            DistributionBranchSet,
600
587
            )
 
588
        from bzrlib.plugins.builddeb.util import (
 
589
            component_from_orig_tarball,
 
590
            )
601
591
        db = DistributionBranch(tree.branch, tree.branch, tree=tree)
602
592
        dbs = DistributionBranchSet()
603
593
        dbs.add_branch(db)
611
601
 
612
602
    def _fetch_tarball(self, package, version, orig_dir, locations, v3):
613
603
        from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
 
604
        from bzrlib.plugins.builddeb.util import tarball_name
614
605
        ret = []
615
606
        format = None
616
607
        for location in locations:
642
633
            locations, v3)
643
634
 
644
635
    def _get_changelog_info(self, tree, last_version, package, distribution):
 
636
        from bzrlib.plugins.builddeb.util import (
 
637
            find_changelog,
 
638
            find_last_distribution,
 
639
            lookup_distribution,
 
640
            )
 
641
        from bzrlib.plugins.builddeb.errors import (
 
642
            MissingChangelogError,
 
643
            )
645
644
        current_version = last_version
646
645
        try:
647
646
            (changelog, top_level) = find_changelog(tree, False, max_blocks=2)
677
676
            distribution=None, package=None,
678
677
            directory=".", revision=None, merge_type=None,
679
678
            last_version=None, force=None, snapshot=False, launchpad=False):
 
679
        try:
 
680
            from debian.changelog import Version
 
681
        except ImportError:
 
682
            # Prior to 0.1.15 the debian module was called debian_bundle
 
683
            from debian_bundle.changelog import Version
 
684
 
 
685
        from bzrlib.plugins.builddeb.errors import PackageVersionNotPresent
 
686
        from bzrlib.plugins.builddeb.hooks import run_hook
680
687
        from bzrlib.plugins.builddeb.upstream import (
681
 
                TarfileSource,
682
 
                UScanSource,
683
 
                )
 
688
            TarfileSource,
 
689
            UScanSource,
 
690
            )
684
691
        from bzrlib.plugins.builddeb.upstream.branch import (
685
 
                UpstreamBranchSource,
686
 
                )
 
692
            UpstreamBranchSource,
 
693
            )
 
694
        from bzrlib.plugins.builddeb.util import (
 
695
            FORMAT_3_0_QUILT,
 
696
            FORMAT_3_0_NATIVE,
 
697
            get_source_format,
 
698
            guess_build_type,
 
699
            tree_contains_upstream_source,
 
700
            )
687
701
 
688
702
        tree, _ = WorkingTree.open_containing(directory)
689
703
        tree.lock_write()
873
887
 
874
888
    def import_many(self, db, files_list, orig_target):
875
889
        from bzrlib.plugins.builddeb.import_dsc import (
876
 
                DscCache,
877
 
                DscComp,
878
 
                )
 
890
            DscCache,
 
891
            DscComp,
 
892
            )
 
893
        from bzrlib.plugins.builddeb.util import (
 
894
            open_file_via_transport,
 
895
            )
879
896
        cache = DscCache()
880
897
        files_list.sort(cmp=DscComp(cache).cmp)
881
898
        if not os.path.exists(orig_target):
899
916
            db.import_package(os.path.join(orig_target, filename))
900
917
 
901
918
    def run(self, files_list, file=None):
 
919
        from bzrlib.plugins.builddeb.errors import (
 
920
            MissingChangelogError,
 
921
            )
902
922
        from bzrlib.plugins.builddeb.import_dsc import (
903
923
            DistributionBranch,
904
924
            DistributionBranchSet,
905
925
            )
 
926
        from bzrlib.plugins.builddeb.util import (
 
927
            find_changelog,
 
928
            open_file,
 
929
            )
906
930
        try:
907
931
            tree = WorkingTree.open_containing('.')[0]
908
932
        except NotBranchError:
1009
1033
    takes_args = ['version', 'location', 'upstream_branch?']
1010
1034
 
1011
1035
    def run(self, version, location, upstream_branch=None, revision=None):
 
1036
        try:
 
1037
            from debian.changelog import Version
 
1038
        except ImportError:
 
1039
            # Prior to 0.1.15 the debian module was called debian_bundle
 
1040
            from debian_bundle.changelog import Version
1012
1041
        from bzrlib.plugins.builddeb.import_dsc import (
1013
1042
            DistributionBranch,
1014
1043
            DistributionBranchSet,
1015
1044
            )
 
1045
        from bzrlib.plugins.builddeb.util import (
 
1046
            md5sum_filename,
 
1047
            )
1016
1048
        # TODO: search for similarity etc.
1017
1049
        version = version.encode('utf8')
1018
1050
        branch, _ = Branch.open_containing('.')
1105
1137
    aliases = ['bd-do']
1106
1138
 
1107
1139
    def run(self, command_list=None):
 
1140
        import subprocess
 
1141
        from bzrlib.plugins.builddeb.errors import (
 
1142
            BuildFailedError,
 
1143
            )
1108
1144
        from bzrlib.plugins.builddeb.source_distiller import (
1109
1145
            MergeModeDistiller,
1110
1146
            )
1120
1156
        from bzrlib.plugins.builddeb.upstream.pristinetar import (
1121
1157
            PristineTarSource,
1122
1158
            )
 
1159
        from bzrlib.plugins.builddeb.hooks import run_hook
 
1160
        from bzrlib.plugins.builddeb.util import (
 
1161
            find_changelog,
 
1162
            )
1123
1163
        t = WorkingTree.open_containing('.')[0]
1124
1164
        config = debuild_config(t, t)
1125
1165
        if config.build_type != BUILD_TYPE_MERGE:
1207
1247
            DistributionBranch,
1208
1248
            DistributionBranchSet,
1209
1249
            )
 
1250
        from bzrlib.plugins.builddeb.util import (
 
1251
            find_changelog,
 
1252
            )
1210
1253
        t = WorkingTree.open_containing('.')[0]
1211
1254
        t.lock_write()
1212
1255
        try: