Esempio n. 1
0
 def test_self_deleting_temp_directory(self):
     with utils.SelfDeletingTempDirectory() as tmp:
         self.assert_(isinstance(tmp, six.string_types))
         self.assert_(os.path.exists(tmp))
         self.assert_(os.path.isdir(tmp))
     # Directory shoud be deleted after exiting the block
     self.assertFalse(os.path.exists(tmp))
Esempio n. 2
0
 def test_folder_size_no_ignore(self):
     with utils.SelfDeletingTempDirectory() as tmpdir:
         # write 5 files of 100 bytes each
         for idx in six.moves.range(5):
             pth = os.path.join(tmpdir, "test%s" % idx)
             with open(pth, "w") as ff:
                 ff.write(FAKE_CONTENT)
         fsize = utils.folder_size(tmpdir)
     self.assertEqual(fsize, 500)
Esempio n. 3
0
import pyos
import pyos.exceptions as exc
import pyos.utils as utils

pyos.set_setting("identity_type", "rackspace")
creds_file = os.path.expanduser("~/.rackspace_cloud_credentials")
pyos.set_credential_file(creds_file)
cf = pyos.cloudfiles

cont_name = pyos.utils.random_ascii(8)
cont = cf.create_container(cont_name)

# pyos has a utility for creating temporary local directories that clean
# themselves up.
with utils.SelfDeletingTempDirectory() as tmpfolder:
    # Create a bunch of files
    for idx in six.moves.range(13):
        fname = "file_%s" % idx
        pth = os.path.join(tmpfolder, fname)
        with open(pth, "w") as tmp:
            tmp.write("This is some text")
    # Create a subfolder. It will be deleted automatically as part of
    # the cleanup of SelfDeletingTempDirectory.
    subfolder_path = os.path.join(tmpfolder, "subfolder")
    os.mkdir(subfolder_path)
    # Create some files in the subfolder, too.
    for idx in six.moves.range(7):
        fname = "subfile_%s" % idx
        pth = os.path.join(subfolder_path, fname)
        with open(pth, "w") as tmp: