def test03RemoveDAFRecWF(self):
     """Test the removing of directories and files with a name filter.
     """
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     extTree = os.path.join(self.tmpDirectory, 'test', 'test2', 'test3')
     # Create some files
     try:
         f = open(os.path.join(extTree, 'myfile.tmp'), 'wb')
         f.close()
         f = open(os.path.join(extTree, 'myfile2.tmp'), 'wb')
         f.close()
         f = open(os.path.join(extTree, 'myfile.ttt'), 'wb')
         f.close()
         f = open(os.path.join(extTree, 'myfile.h'), 'wb')
         f.close()
     except:
         pass
     self.assertTrue(os.path.isfile(os.path.join(extTree, 'myfile.tmp')))
     # Create a directory called '.tmp'
     DirectoriesAndFilesTools.MKDirs(os.path.join(extTree, 'truc.tmp'))
     self.assertTrue(os.path.isdir(os.path.join(extTree, 'truc.tmp')))
     # Remove files and directories with 'tmp' extention
     DirectoriesAndFilesTools.RMWithFilters(extTree, filters=[
         '.tmp',
     ])
     self.assertFalse(os.path.isfile(os.path.join(extTree, 'myfile.tmp')))
     self.assertFalse(os.path.isfile(os.path.join(extTree, 'myfile2.tmp')))
     self.assertFalse(os.path.isdir(os.path.join(extTree, 'truc.tmp')))
     self.assertTrue(os.path.isdir(extTree))
 def test04CopyTree(self):
     """Test the copying of directories tree.
     """
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     extTree = os.path.join(self.tmpDirectory, 'test2', 'test2', 'test3')
     DirectoriesAndFilesTools.CPDir(
         os.path.join(self.tmpDirectory, 'test'),
         os.path.join(self.tmpDirectory, 'test2'))
     self.assertTrue(os.path.isfile(os.path.join(extTree, 'myfile.ttt')))
 def test05RemoveDAFRec(self):
     """Test the removing of directories tree with files.
     """
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     baseTree = os.path.join(self.tmpDirectory, 'test')
     DirectoriesAndFilesTools.RMDirs(baseTree)
     self.assertFalse(os.path.isdir(baseTree))
     baseTree = os.path.join(self.tmpDirectory, 'test2')
     DirectoriesAndFilesTools.RMDirs(baseTree)
     self.assertFalse(os.path.isdir(baseTree))
 def test02CreateDirectoriesTreeFFS(self):
     """Test the creation of a clean directories tree (Erase the old one).
     """
     # Create a directories tree
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     extTree = os.path.join(self.tmpDirectory, 'test', 'test2', 'test3')
     DirectoriesAndFilesTools.MKDirsF(extTree)
     # Check if the last directory exists
     self.assertTrue(os.path.isdir(extTree))
     # Check if the previously created file still exists
     self.assertFalse(os.path.isfile(os.path.join(extTree, 'myfile.tmp')))
 def test01CreateDirectoriesTree(self):
     """Test the creation of a new directories tree.
     """
     # Create a directories tree
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     extTree = os.path.join(self.tmpDirectory, 'test', 'test2', 'test3')
     DirectoriesAndFilesTools.MKDirs(extTree)
     # Check if the last directory exists
     self.assertTrue(os.path.isdir(extTree))
     # Create a file
     try:
         f = open(os.path.join(extTree, 'myfile.tmp'), 'wb')
         f.close()
     except:
         pass
     self.assertTrue(os.path.isfile(os.path.join(extTree, 'myfile.tmp')))
Ejemplo n.º 6
0
 def __init__(self, cachePrefix="kysohcf"):
     """Constructor of container of cached files object.
     @param cachePrefix: Cache directory location.
     """
     self.__cachePrefix = cachePrefix
     self.__cacheDir = os.path.join(_BASE_TEMP_DIR, self.__cachePrefix)
     DirectoriesAndFilesTools.MKDirsF(self.__cacheDir)
     self.__container = []
Ejemplo n.º 7
0
 def test05DownloadToFile2(self):
     """Test the downloading of a file from a bad URL to a file.
     """
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     res = URLTools.URLDownloadToFile(
         _URL_FILE_TO_TEST + 'xxx',
         os.path.join(self.tmpDirectory, 'temp.tmp'))
     self.assertFalse(res)
     self.assertFalse(
         os.path.isfile(os.path.join(self.tmpDirectory, 'temp.tmp')))
Ejemplo n.º 8
0
 def test04DownloadToFile(self):
     """Test the downloading of a file from a valid URL to a file.
     """
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     res = URLTools.URLDownloadToFile(
         _URL_FILE_TO_TEST, os.path.join(self.tmpDirectory, 'temp.tmp'))
     self.assertTrue(res)
     self.assertTrue(
         os.path.isfile(os.path.join(self.tmpDirectory, 'temp.tmp')))
     os.remove(os.path.join(self.tmpDirectory, 'temp.tmp'))
 def test00GetOSTMPDir(self):
     """Test the retrieving of the temporary directory.
     """
     # Retrieve the temporary directory of the OS.
     self.tmpDirectory = DirectoriesAndFilesTools.GetOSTMPDir()
     self.assertNotEqual(self.tmpDirectory, "")
     # Check the creation of a file in the retrieved directory
     work = True
     try:
         f = open(os.path.join(self.tmpDirectory, "test.tmp"), 'wb')
         f.write("\n")
         f.close()
         os.remove(os.path.join(self.tmpDirectory, "test.tmp"))
     except:
         work = False
     self.assertEqual(work, True)
Ejemplo n.º 10
0
 def __init__(self, uri, cachePrefix="kysohcf"):
     """Constructor of cached file object.
     @param uri: Input file location.
     @param cachePrefix: Cache directory location.
     """
     self.__isValid = True
     self.__cacheDir = os.path.join(_BASE_TEMP_DIR, cachePrefix)
     if not os.path.isdir(self.__cacheDir):
         DirectoriesAndFilesTools.MKDirs(self.__cacheDir)
     self.__uri = uri
     self.__md5Tag = getMD5HashOfURI(uri)
     if self.__md5Tag == "":
         self.__isValid = False
         return
     self.__outputPath = self.__generateOutputFileName()
     if not self.__writeOutputFile():
         self.__isValid = False
         return
Ejemplo n.º 11
0
 def destroy(self):
     """Destroy the cached files container object.
     """
     DirectoriesAndFilesTools.RMDirs(self.__cacheDir)
     self.__container = []
Ejemplo n.º 12
0
 def destroy(self):
     """Destroy the cached file.
     """
     DirectoriesAndFilesTools.RMFile(self.__outputPath)
     self.__isValid = False
Ejemplo n.º 13
0
import os

try:
    from hashlib import md5
except:
    from md5 import md5

if os.name == 'nt':
    import win32con
    import win32file

from URLTools import URLGetInfos, URLDownloadToString
import DirectoriesAndFilesTools

_BASE_TEMP_DIR = DirectoriesAndFilesTools.GetOSTMPDir()

# ==============================================================================
# Public functions
# ==============================================================================


# ------------------------------------------------------------------------------
# Get the MD5 hash code from some informations of a file.
# ------------------------------------------------------------------------------
def getMD5HashOfURI(uri):
    """Get the MD5 hash code from some informations of a file.
    @param uri: File location.
    @return: The MD5 hash code.
    """
    result = ""