Ejemplo n.º 1
0
 def _handle_deletion_errors(self, function, path, info):
     """try to close the file if it's a file """
     logger.log_warning('in run_manager._handle_deletion_errors: Trying  to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
     if function.__name__ == 'remove':
         try:
             logger.disable_all_file_logging()
             file = open(path)
             file.close()
             os.remove(path)
         except:
             logger.log_warning('in run_manager._handle_deletion_errors:unable to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
     else:
         logger.log_warning('in run_manager._handle_deletion_errors:unable to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
Ejemplo n.º 2
0
 def _handle_deletion_errors(self, function, path, info):
     """try to close the file if it's a file """
     logger.log_warning('in run_manager._handle_deletion_errors: Trying  to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
     if function.__name__ == 'remove':
         try:
             logger.disable_all_file_logging()
             file = open(path)
             file.close()
             os.remove(path)
         except:
             logger.log_warning('in run_manager._handle_deletion_errors:unable to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
     else:
         logger.log_warning('in run_manager._handle_deletion_errors:unable to delete %s error from function %s: \n %s' % (path,function.__name__,info[1]))
Ejemplo n.º 3
0
 def test_delete_some_years(self):            
     cache_dir = self.resources['cache_directory']
     self.assert_(os.path.exists(cache_dir))
     self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
     path = module_path_from_opus_path('opus_core.tools.delete_run')
     
     cmd_template = sys.executable + ' %(path)s --run-id=%(run_id)d --years-to-delete=%(years_to_delete)s --services_database=services_test'
     
     # First just delete 2 years of data.
     python_cmd = cmd_template % {
         'path':path,
         'run_id':self.resources['run_id'],
         'years_to_delete':'[1982,1983]'}
     
     # Close all log files so we can delete the cache.
     logger.disable_all_file_logging()
     self.do_cmd(python_cmd)
     self.assert_(os.path.exists(cache_dir))
     self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
     self.assert_(os.path.exists(os.path.join(cache_dir, '1984')))
     
     # Now see if we can delete another year of data.
     python_cmd = cmd_template % {
         'path':path,
         'run_id':self.resources['run_id'],
         'years_to_delete':'1984'}
     # Close all log files so we can delete the cache.
     logger.disable_all_file_logging()
     self.do_cmd(python_cmd)
     self.assert_(os.path.exists(cache_dir))
     self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1984')))
     
     # Trying to delete the same year again should be a no-op.
     python_cmd = cmd_template % {
         'path':path,
         'run_id':self.resources['run_id'],
         'years_to_delete':'1982'}
     # Close all log files so we can delete the cache.
     logger.disable_all_file_logging()
     self.do_cmd(python_cmd)
     self.assert_(os.path.exists(cache_dir))
     self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
     self.assert_(not os.path.exists(os.path.join(cache_dir, '1984')))
     
     # Now try to delete the rest of the years of data
     python_cmd = '%(executable)s %(path)s --run-id=%(run_id)d --services_database=services_test' % {
         'executable':sys.executable,
         'path':path,
         'run_id':self.resources['run_id']}
     # Close all log files so we can delete the cache.
     logger.disable_all_file_logging()
     self.do_cmd(python_cmd)
     self.assert_(not os.path.exists(cache_dir))
Ejemplo n.º 4
0
 def tearDown(self):
     # Turn off the logger, so we can delete the cache directory.
     logger.disable_all_file_logging()
     db_server = DatabaseServer(self.config)
     db_server.drop_database('eugene_services_test')
     db_server.close()
 def tearDown(self):
     # Turn off the logger, so we can delete the cache directory.
     logger.disable_all_file_logging()
     db_server = DatabaseServer(self.config)
     db_server.drop_database("eugene_services_test")
     db_server.close()
Ejemplo n.º 6
0
    def test_delete_some_years(self):
        cache_dir = self.resources['cache_directory']
        self.assert_(os.path.exists(cache_dir))
        self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
        path = module_path_from_opus_path('opus_core.tools.delete_run')

        cmd_template = sys.executable + ' %(path)s --run-id=%(run_id)d --years-to-delete=%(years_to_delete)s --services_database=services_test'

        # First just delete 2 years of data.
        python_cmd = cmd_template % {
            'path': path,
            'run_id': self.resources['run_id'],
            'years_to_delete': '[1982,1983]'
        }

        # Close all log files so we can delete the cache.
        logger.disable_all_file_logging()
        self.do_cmd(python_cmd)
        self.assert_(os.path.exists(cache_dir))
        self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
        self.assert_(os.path.exists(os.path.join(cache_dir, '1984')))

        # Now see if we can delete another year of data.
        python_cmd = cmd_template % {
            'path': path,
            'run_id': self.resources['run_id'],
            'years_to_delete': '1984'
        }
        # Close all log files so we can delete the cache.
        logger.disable_all_file_logging()
        self.do_cmd(python_cmd)
        self.assert_(os.path.exists(cache_dir))
        self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1984')))

        # Trying to delete the same year again should be a no-op.
        python_cmd = cmd_template % {
            'path': path,
            'run_id': self.resources['run_id'],
            'years_to_delete': '1982'
        }
        # Close all log files so we can delete the cache.
        logger.disable_all_file_logging()
        self.do_cmd(python_cmd)
        self.assert_(os.path.exists(cache_dir))
        self.assert_(os.path.exists(os.path.join(cache_dir, '1981')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1982')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1983')))
        self.assert_(not os.path.exists(os.path.join(cache_dir, '1984')))

        # Now try to delete the rest of the years of data
        python_cmd = '%(executable)s %(path)s --run-id=%(run_id)d --services_database=services_test' % {
            'executable': sys.executable,
            'path': path,
            'run_id': self.resources['run_id']
        }
        # Close all log files so we can delete the cache.
        logger.disable_all_file_logging()
        self.do_cmd(python_cmd)
        self.assert_(not os.path.exists(cache_dir))