[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a
Garrett Holmstrom
gholms at fedoraproject.org
Sun Jun 16 02:31:21 UTC 2013
The following commit has been merged in the master branch:
commit bd7ace30b36aa5e0e6eff71308b9deb1cad34aa8
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Thu May 9 15:52:43 2013 -0700
Make mkdtemp_for_large_files its own function
diff --git a/euca2ools/commands/bundle/bundleimage.py b/euca2ools/commands/bundle/bundleimage.py
index 63782de..d8cc012 100644
--- a/euca2ools/commands/bundle/bundleimage.py
+++ b/euca2ools/commands/bundle/bundleimage.py
@@ -35,6 +35,7 @@ from euca2ools.commands import Euca2ools
from euca2ools.commands.argtypes import delimited_list, filesize
from euca2ools.commands.bundle import add_bundle_creds
from euca2ools.commands.bundle.bundle import Bundle
+from euca2ools.utils import mkdtemp_for_large_files
import hashlib
import lxml.etree
import lxml.objectify
@@ -45,7 +46,6 @@ from requestbuilder.exceptions import ArgumentError
from requestbuilder.mixins import FileTransferProgressBarMixin
from requestbuilder.util import set_userregion
import subprocess
-import tempfile
def manifest_block_device_mappings(mappings_as_str):
@@ -164,9 +164,7 @@ class BundleImage(BaseCommand, FileTransferProgressBarMixin):
if not os.path.exists(self.args['destination']):
os.mkdir(self.args['destination'])
else:
- tempdir_base = (os.getenv('TMPDIR') or os.getenv('TEMP') or
- os.getenv('TMP') or '/var/tmp')
- tempdir = tempfile.mkdtemp(prefix='bundle-', dir=tempdir_base)
+ tempdir = mkdtemp_for_large_files(prefix='bundle-')
path_prefix = os.path.join(tempdir, prefix)
self.log.debug('bundle path prefix: %s', path_prefix)
diff --git a/euca2ools/commands/bundle/downloadbundle.py b/euca2ools/commands/bundle/downloadbundle.py
index 6fe1c69..0f65718 100644
--- a/euca2ools/commands/bundle/downloadbundle.py
+++ b/euca2ools/commands/bundle/downloadbundle.py
@@ -34,12 +34,12 @@ from euca2ools.commands.bundle.helpers import get_manifest_parts
from euca2ools.commands.walrus import WalrusRequest
from euca2ools.commands.walrus.checkbucket import CheckBucket
from euca2ools.exceptions import AWSError
+from euca2ools.utils import mkdtemp_for_large_files
import os
from requestbuilder import Arg, MutuallyExclusiveArgList
from requestbuilder.exceptions import ArgumentError
import shutil
import sys
-import tempfile
class DownloadBundle(WalrusRequest):
@@ -106,7 +106,7 @@ class DownloadBundle(WalrusRequest):
CheckBucket(bucket=bucket, service=self.service,
config=self.config).main()
- directory = self.args.get('directory') or tempfile.mkdtemp()
+ directory = self.args.get('directory') or mkdtemp_for_large_files()
if not os.path.isdir(directory):
raise ArgumentError(
"location '{0}' is either not a directory or does not exist."
@@ -117,6 +117,4 @@ class DownloadBundle(WalrusRequest):
else:
self._download_by_prefix(directory)
- # Print location if we used a temp directory
- if not self.args.get('directory'):
- print >> sys.stderr, "Bundle downloaded to '{0}'".format(directory)
+ print "Bundle downloaded to '{0}'".format(directory)
diff --git a/euca2ools/commands/eustore/installimage.py b/euca2ools/commands/eustore/installimage.py
index 5e1ab9b..e40aef2 100644
--- a/euca2ools/commands/eustore/installimage.py
+++ b/euca2ools/commands/eustore/installimage.py
@@ -40,6 +40,7 @@ from euca2ools.commands.euca.registerimage import RegisterImage
from euca2ools.commands.eustore import EuStoreRequest
import euca2ools.commands.eustore.describeimages
from euca2ools.commands.walrus import Walrus
+from euca2ools.utils import mkdtemp_for_large_files
import hashlib
import os.path
from requestbuilder import Arg, MutuallyExclusiveArgList
@@ -51,7 +52,6 @@ from requestbuilder.util import set_userregion
import shutil
import sys
import tarfile
-import tempfile
import urlparse
import zlib
@@ -195,10 +195,7 @@ class InstallImage(EuStoreRequest, FileTransferProgressBarMixin):
workdir = self.args['directory']
should_delete_workdir = False
else:
- # We do this by hand to default to /var/tmp instead of /tmp.
- workdir_base = (os.getenv('TMPDIR') or os.getenv('TEMP') or
- os.getenv('TMP') or '/var/tmp')
- workdir = tempfile.mkdtemp(dir=workdir_base)
+ workdir = mkdtemp_for_large_files()
self.log.debug('created working directory %s', workdir)
should_delete_workdir = True
diff --git a/euca2ools/utils.py b/euca2ools/utils.py
index db489bb..1b046a4 100644
--- a/euca2ools/utils.py
+++ b/euca2ools/utils.py
@@ -35,6 +35,7 @@ import base64
import os.path
import subprocess
import sys
+import tempfile
from euca2ools import exceptions, __version__
def check_prerequisite_command(command):
@@ -161,3 +162,17 @@ def build_progressbar_label_template(fnames):
return fmt_template.format(maxlen=max_fname_len,
lenlen=len(str(len(fnames))),
total=len(fnames))
+
+
+def mkdtemp_for_large_files(suffix='', prefix='tmp', dir=None):
+ '''
+ Like tempfile.mkdtemp, but using /var/tmp as a last resort instead of /tmp.
+
+ This is meant for utilities that create large files, as /tmp is often a
+ ramdisk.
+ '''
+
+ if dir is None:
+ dir = (os.getenv('TMPDIR') or os.getenv('TEMP') or os.getenv('TMP') or
+ '/var/tmp')
+ return tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list