Exemplo n.º 1
0
 def test_copy_hardlink(self):
     """
     Test copy with hardlinks: we create a file in data_dir and try to
     link it. This should work unless /tmp don't accept hardlinks.
     """
     # Create a file and a directory in data_dir. We don't destroy them
     # since they are in /tmp.
     _, orig_file_full = tempfile.mkstemp(dir=self.utils.data_dir)
     orig_file = os.path.basename(orig_file_full)
     to_dir = tempfile.mkdtemp(dir=self.utils.data_dir)
     new_file_full = os.path.join(to_dir, orig_file)
     # Copy
     from_dir = self.utils.data_dir
     files_to_copy = [{'root': from_dir, 'name': orig_file}]
     Utils.copy_files(files_to_copy, to_dir, use_hardlinks=True)
     # Check if file was copied
     self.assertTrue(os.path.exists(new_file_full))
     # Check if it's really a hardlink. This may fail so we catch
     # any exceptions.
     orig_file_stat = os.stat(orig_file_full)
     new_file_stat = os.stat(new_file_full)
     try:
         self.assertTrue(orig_file_stat.st_ino == new_file_stat.st_ino)
     except Exception:
         msg = "In %s: copy worked but hardlinks were not used." % self.id()
         print(msg, file=sys.stderr)
Exemplo n.º 2
0
 def test_copy(self):
     from_dir = os.path.dirname(os.path.realpath(__file__))
     local_file = 'biomaj_tests.py'
     files_to_copy = [{'root': from_dir, 'name': local_file}]
     to_dir = self.utils.data_dir
     Utils.copy_files(files_to_copy, to_dir)
     self.assertTrue(os.path.exists(to_dir + '/biomaj_tests.py'))
Exemplo n.º 3
0
    def test_uncompress(self):
        from_file = {
            'root': os.path.dirname(os.path.realpath(__file__)),
            'name': 'bank/test.fasta.gz'
        }

        to_dir = self.utils.data_dir
        Utils.copy_files([from_file], to_dir)
        Utils.uncompress(os.path.join(to_dir, from_file['name']))
        self.assertTrue(os.path.exists(to_dir + '/bank/test.fasta'))
Exemplo n.º 4
0
    def download(self, local_dir):
        '''
        Copy local files to local_dir

        :param local_dir: Directory where files should be copied
        :type local_dir: str
        :return: list of downloaded files
        '''
        self.logger.debug('Local:Download')
        Utils.copy_files(self.files_to_download,
                         local_dir,
                         use_hardlinks=self.use_hardlinks,
                         lock=self.mkdir_lock)
        for rfile in self.files_to_download:
            rfile['download_time'] = 0

        return self.files_to_download