Exemplo n.º 1
0
    def create_file(self):
        '''Prior creating a file, we first decide which type of file to create'''
        file_type = self.file_system.get_fitness_proportionate_element(self.stereotype_file_types_probabilities)
        
        '''After choosing the type, we proceed by generating the size of the file'''           
        (function, kv_params) = self.file_types_sizes[file_type]
        size = int(get_random_value_from_fitting(function, kv_params))

        '''Ensure that files are not huge'''
        if size > FILE_SIZE_MAX: 
            size = FILE_SIZE_MAX

        '''After generating the file size, we should decide the path for the new file'''
        synthetic_file_base_path = self.file_system.get_random_fs_directory(FS_SNAPSHOT_PATH)
        '''Create a realistic name'''
        synthetic_file_base_path += get_random_alphanumeric_string(random.randint(1,20)) + \
                                    self.r.choice(self.stereotype_file_types_extensions[file_type])
         
        
        '''Invoke SDGen to generate realistic file contents'''
        characterization = DATA_CHARACTERIZATIONS_PATH + file_type
        success = True
        if not DEBUG:
            try:
                '''Decide whether we have to create a new file or to take deduplicated content'''
                if self.file_level_deduplication_ratio < self.r.random():
                    cp = subprocess.call(['java', '-jar', DATA_GENERATOR_PATH, characterization, str(size), synthetic_file_base_path], cwd=DATA_GENERATOR_PROPERTIES_DIR)
                    print "--------------------------------------------------------"
                    print "CREATING [NEW] FILE: ", synthetic_file_base_path, str(size)                         
                else: 
                    '''Get a random file as content and store it with a new name'''
                    src_path, file_type = self.file_system.get_file_based_on_type_popularity(self.stereotype_file_types_probabilities, self.stereotype_file_types_extensions)
                    if src_path== None: 
                        return None
                    print "--------------------------------------------------------"
                    print "CREATING [DEDUPLICATED] FILE: ", synthetic_file_base_path, str(size)  
                    shutil.copyfile(src_path, synthetic_file_base_path)
            except Exception as ex:
                print ex
                success = False
                                        
        if success: 
            self.file_system.add_node_to_fs(synthetic_file_base_path)
            return synthetic_file_base_path
        
        return None
Exemplo n.º 2
0
 def create_directory(self):
     print "--------------------------------------------------------"
     '''Pick a random position in the fs hierarchy (consider only dirs)'''
     directory_path = self.file_system.get_random_fs_directory(FS_SNAPSHOT_PATH)
     to_create = directory_path + get_random_alphanumeric_string()
     print "CREATING DIRECTORY: ", to_create
     success = True
     if not DEBUG:
         try:
             os.makedirs(to_create)
         except Exception as ex:
             print ex
             success = False
             
     if success:
         self.file_system.add_node_to_fs(to_create)
         return to_create
     
     return None