~ubuntu-branches/ubuntu/oneiric/bzr-builddeb/oneiric

« back to all changes in this revision

Viewing changes to repack_tarball.py

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, James Westby, Jelmer Vernooij
  • Date: 2010-08-18 20:12:20 UTC
  • mfrom: (5.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100818201220-yblzkx1w097ohh7h
Tags: 2.6
[ James Westby ]

* Don't fail if asked to use a .bz2 tarball that is already in the desired
  location. LP: #616786
* Don't crash if we are asked to merge-upstream with an unrelated branch.
  LP: #619614.
* Don't strip -n from the version we get in merge-upstream, as some
  upstreams have this in there, and trying to support both means supporting
  both badly. If you are used to doing "bzr merge-upstream --version
  <package version>" then it will no longer work for you, use the
  upstream version instead.
* Don't crash when doing merge-upstream with a branch that does a rename
  and then ships another file with the old path in the tarball that isn't
  in the branch.

[ Jelmer Vernooij ]

* Fix the auto-detection of merge mode.
* Don't crash on merge mode packages where there is no export-upstream
  if we can't find the tarball.
* Determine Bazaar home directory using bzrlib to prevent test
  isolation issues. LP: #614125

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
            zip.close()
124
124
 
125
125
 
 
126
def get_filetype(filename):
 
127
    types = [".tar.gz", ".tgz", ".tar.bz2", ".tbz2", ".tar", ".zip"]
 
128
    for filetype in types:
 
129
        if filename.endswith(filetype):
 
130
            return filetype
 
131
 
 
132
 
126
133
def get_repacker_class(source_filename, force_gz=True):
127
134
    """Return the appropriate repacker based on the file extension."""
128
 
    if (source_filename.endswith(".tar.gz")
129
 
            or source_filename.endswith(".tgz")):
 
135
    filetype = get_filetype(source_filename)
 
136
    if (filetype == ".tar.gz" or filetype == ".tgz"):
130
137
        return TgzTgzRepacker
131
 
    if (source_filename.endswith(".tar.bz2")
132
 
            or source_filename.endswith(".tbz2")):
 
138
    if (filetype == ".tar.bz2" or filetype == ".tbz2"):
133
139
        if force_gz:
134
140
            return Tbz2TgzRepacker
135
141
        return TgzTgzRepacker
136
 
    if source_filename.endswith(".tar"):
 
142
    if filetype == ".tar":
137
143
        return TarTgzRepacker
138
 
    if source_filename.endswith(".zip"):
 
144
    if filetype == ".zip":
139
145
        return ZipTgzRepacker
140
146
    return None
141
147
 
142
148
 
143
 
def _error_if_exists(target_transport, new_name, source_name):
144
 
    if not source_name.endswith('.tar.gz'):
 
149
def _error_if_exists(target_transport, new_name, source_name, force_gz=True):
 
150
    source_filetype = get_filetype(source_name)
 
151
    if force_gz and source_filetype != ".tar.gz":
145
152
        raise FileExists(new_name)
146
153
    source_f = open_file(source_name)
147
154
    try:
226
233
    extra, new_name = os.path.split(new_name)
227
234
    target_transport = get_transport(os.path.join(target_dir, extra))
228
235
    if target_transport.has(new_name):
229
 
        _error_if_exists(target_transport, new_name, source_name)
 
236
        _error_if_exists(target_transport, new_name, source_name,
 
237
                force_gz=force_gz)
230
238
        return
231
239
    if os.path.isdir(source_name):
232
240
        _repack_directory(target_transport, new_name, source_name)