def installve(self, location, sudo_user=None, run_local=False): '''Install latest virtualenv. :param location: base directory to install virtualenv :param sudo_user: user to sudo as (assumes run_local=False) :param run_local: run commands locally (False by default) ''' runner = self.runner_factory(sudo_user=sudo_user, run_local=run_local) url = VE_DOWNLOAD parts = urlparse.urlparse(url) name = os.path.basename(parts.path) with runner.cd('/tmp'): runner.run('wget %s -O %s' % (url, name)) archive = Archive('/tmp/' + name) archive._runner = runner archive.extractall(location) newdir = location + '/' + name if newdir.endswith('.tar.gz'): newdir = newdir[:-7] elif newdir.endswith('.tar.bz2'): newdir = newdir[:8] else: s = newdir.rsplit('.', 1) if len(s) > 1: newdir = s[0] runner.run('rm -f %s/virtualenv' % location) runner.run('ln -s %s %s/virtualenv' % (newdir, location))
def _test_archive(self, archivename, type_): from applib import sh from serverzen_fabric.archive import Archive import os name1 = 'hellworld.txt' text1 = 'random text' fname = self.newfile(name1, text1) tempdir1 = self.mkdtemp('tempdir1-' + archivename) tarball = os.path.join(tempdir1, archivename) sh.pack_archive(tarball, [fname], os.path.dirname(fname), type_) tempdir2 = self.mkdtemp('tempdir2-' + archivename) arc = Archive(tarball) arc.extractall(tempdir2, run_local=True) self.assertTrue(name1 in os.listdir(tempdir2), 'File not extracted properly') self.assertEqual(text1, open(os.path.join(tempdir2, name1)).read())