~ubuntu-langpack/langpack-o-matic/main

« back to all changes in this revision

Viewing changes to lib/tarball.py

  • Committer: martin at piware
  • Date: 2006-03-31 16:46:38 UTC
  • Revision ID: martin@piware.de-20060331164638-a0b6ed2926666a3c
combined changes from breezy to head from old revision control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''Convenience methods for tarball handling.'''
 
2
 
 
3
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
 
4
# (C) 2005 Canonical Ltd.
 
5
 
 
6
import os, tarfile
 
7
 
 
8
def untar(tar, path):
 
9
    '''Extract given tarball to path.'''
 
10
 
 
11
    tar = tarfile.open(tar)
 
12
    curdir = os.getcwd()
 
13
    os.chdir(path)
 
14
    for m in tar.getmembers():
 
15
        tar.extract(m)
 
16
    os.chdir(curdir)
 
17
    tar.close()
 
18
 
 
19
def tar(path, tar, gz = True):
 
20
    '''Create a tarball from given directory.'''
 
21
 
 
22
    if gz:
 
23
        tar = tarfile.open(tar, 'w:gz')
 
24
    else:
 
25
        tar = tarfile.open(tar, 'w:')
 
26
    curdir = os.getcwd()
 
27
    os.chdir(path)
 
28
    tar.add('.')
 
29
    os.chdir(curdir)
 
30
    tar.close()
 
31