def testMkDirsGlobAndRmDirs(self):
     self.assertFalse(gfile.Exists(self.tmp + "test_dir"))
     gfile.MkDir(self.tmp + "test_dir")
     self.assertTrue(gfile.Exists(self.tmp + "test_dir"))
     gfile.RmDir(self.tmp + "test_dir")
     self.assertFalse(gfile.Exists(self.tmp + "test_dir"))
     gfile.MakeDirs(self.tmp + "test_dir/blah0")
     gfile.MakeDirs(self.tmp + "test_dir/blah1")
     self.assertEqual(
         [self.tmp + "test_dir/blah0", self.tmp + "test_dir/blah1"],
         sorted(gfile.Glob(self.tmp + "test_dir/*")))
     gfile.DeleteRecursively(self.tmp + "test_dir")
     self.assertFalse(gfile.Exists(self.tmp + "test_dir"))
示例#2
0
文件: base.py 项目: StryxZilla/tensor
def maybe_download(filename, work_directory, source_url):
    """Download the data from source url, unless it's already here."""
    if not gfile.Exists(work_directory):
        gfile.MakeDirs(work_directory)
    filepath = os.path.join(work_directory, filename)
    if not gfile.Exists(filepath):
        with tempfile.NamedTemporaryFile() as tmpfile:
            temp_file_name = tmpfile.name
            urllib.request.urlretrieve(source_url, temp_file_name)
            gfile.Copy(temp_file_name, filepath)
            with gfile.GFile(filepath) as f:
                size = f.Size()
            print('Successfully downloaded', filename, size, 'bytes.')
    return filepath
示例#3
0
def maybe_download(filename, work_directory, source_url):
    """Download the data from source url, unless it's already here.

    Args:
        filename: string, name of the file in the directory.
        work_directory: string, path to working directory.
        source_url: url to download from if file doesn't exist.

    Returns:
        Path to resulting file.
    """
    if not gfile.Exists(work_directory):
        gfile.MakeDirs(work_directory)
    filepath = os.path.join(work_directory, filename)
    if not gfile.Exists(filepath):
        with tempfile.NamedTemporaryFile() as tmpfile:
            temp_file_name = tmpfile.name
            urllib.request.urlretrieve(source_url, temp_file_name)
            gfile.Copy(temp_file_name, filepath)
        with gfile.GFile(filepath) as f:
            size = f.Size()
        print('Successfully downloaded', filename, size, 'bytes.')
    return filepath
 def testMakeDirsWithEmptyString(self):
     gfile.MakeDirs(self.tmp + "test_dir")
     with self._working_directory(self.tmp + "test_dir"):
         gfile.MakeDirs("")
     # Should succeed because MakeDirs("") is a no-op.
     gfile.RmDir(self.tmp + "test_dir")