예제 #1
0
파일: strategy.py 프로젝트: dtgit/dtedu
 def setValueFile(self, value, **kwargs):
     """Copy file value on filesystem"""
     
     # Get filename of value file
     name = kwargs['name']
     path = self.getValueDirectoryPath(**kwargs)
     
     # Remove old files (value and rdf files)
     file_path = self.getValueFilePath(**kwargs)
     if os.path.exists(file_path):
         rm_file(file_path)
     rdf_path = self.getRDFFilePath(**kwargs)
     if os.path.exists(rdf_path):
         rm_file(rdf_path)
     self.unsetFilenameInConfigFile(path, name)
        
     # Process new filename
     filename = self.getValueFilename(**kwargs)
     
     # Update config file
     self.createSubDirectories(path, self.storage_path)
     self.setFilenameInConfigFile(path, name, filename)
     
     # Store value
     FlatStorageStrategy.setValueFile(self, value, **kwargs)
예제 #2
0
파일: strategy.py 프로젝트: dtgit/dtedu
 def unsetRDFFile(self, **kwargs):
     """Remove rdf file if exists"""
     
     # This is a cut/paste operation. There is no need to delete file
     if kwargs.get('is_moved', False):
         return
     
     rdf_path = self.getRDFFilePath(**kwargs)
     if not os.path.exists(rdf_path):
         return
     rm_file(rdf_path)
예제 #3
0
파일: strategy.py 프로젝트: dtgit/dtedu
    def setValueFile(self, value, **kwargs):
        """Copy file value on filesystem"""

        # Remove all files in value directory except rdf file
        path = self.getValueDirectoryPath(**kwargs)

        if os.path.exists(path):
            rdf_filename = self.getRDFFilename(**kwargs)
            for filename in os.listdir(path):
                if filename == rdf_filename:
                    continue
                file_path = os.path.join(path, filename)
                rm_file(file_path)
                
        DirectoryStorageStrategy.setValueFile(self, value, **kwargs)
예제 #4
0
파일: FSSTool.py 프로젝트: dtgit/ecec
    def removeBackups(self, max_days):
        """
        Remove backups older than specified days
        """

        backup_brains = self.getBackupBrains()
        valid_backups = [x for x in backup_brains if x["path"] is None]
        current_time = time.time()

        for item in valid_backups:
            one_day = 86400  # One day 86400 seconds
            modified = item["modified"]
            seconds = int(current_time) - int(modified.timeTime())
            days = int(seconds / one_day)

            if days >= max_days:
                rm_file(item["fs_path"])
예제 #5
0
파일: strategy.py 프로젝트: dtgit/dtedu
 def unsetFilenameInConfigFile(self, root_path, name):
     """Remove filename field association in config file
     
     @root_path: Path where config file is stored
     @param name: Field name
     """
     
     path = os.path.join(root_path, self.cfg_filename)
     
     # Config file doesn't exists
     if not os.path.exists(path):
         return
     
     # Initialize config file
     config = RawConfigParser()
     
     # Read old config file
     fd = open(path, 'r')
     try:
         # Read file
         config.readfp(fd)
     finally:
         fd.close()
     
     # Update config file
     if config.has_section(self.cfg_filename_section):
         config.remove_option(self.cfg_filename_section, name)
     
     if not config.options(self.cfg_filename_section):
         # Section is empty so remove config file
         rm_file(path)
     else:
         fd = open(path, 'w')
         try:
             # Write file
             config.write(fd)
         finally:
             fd.close()