def test_compress(self): filepath = utils.TEST_ROOT self.assertFalse( utils.attributes(filepath) & win32file.FILE_ATTRIBUTE_COMPRESSED) for filename in self.filenames: self.assertFalse( utils.attributes(os.path.join(filepath, filename)) & win32file.FILE_ATTRIBUTE_COMPRESSED) fs.Dir(filepath).compress() self.assertTrue( utils.attributes(filepath) & win32file.FILE_ATTRIBUTE_COMPRESSED) for filename in self.filenames: self.assertTrue( utils.attributes(os.path.join(filepath, filename)) & win32file.FILE_ATTRIBUTE_COMPRESSED) fs.Dir(filepath).uncompress() self.assertFalse( utils.attributes(filepath) & win32file.FILE_ATTRIBUTE_COMPRESSED) for filename in self.filenames: self.assertFalse( utils.attributes(os.path.join(filepath, filename)) & win32file.FILE_ATTRIBUTE_COMPRESSED)
def test_unencrypt_not_contents(self): filepath = utils.TEST_ROOT fs.Dir(filepath).encrypt() self.assertTrue(utils.attributes(filepath) & FILE_ATTRIBUTE_ENCRYPTED) for filename in self.filenames: self.assertTrue( utils.attributes(os.path.join(filepath, filename)) & FILE_ATTRIBUTE_ENCRYPTED) fs.Dir(filepath).unencrypt(apply_to_contents=False) self.assertFalse(utils.attributes(filepath) & FILE_ATTRIBUTE_ENCRYPTED) for filename in self.filenames: self.assertTrue( utils.attributes(os.path.join(filepath, filename)) & FILE_ATTRIBUTE_ENCRYPTED)
def test_encrypt(self): filepath = utils.TEST_ROOT self.assertFalse(utils.attributes(filepath) & FILE_ATTRIBUTE_ENCRYPTED) for filename in self.filenames: self.assertFalse( utils.attributes(os.path.join(filepath, filename)) & FILE_ATTRIBUTE_ENCRYPTED) fs.Dir(filepath).encrypt() self.assertTrue(utils.attributes(filepath) & FILE_ATTRIBUTE_ENCRYPTED) for filename in self.filenames: self.assertTrue( utils.attributes(os.path.join(filepath, filename)) & FILE_ATTRIBUTE_ENCRYPTED) fs.Dir(filepath).unencrypt() self.assertFalse(utils.attributes(filepath) & FILE_ATTRIBUTE_ENCRYPTED) for filename in self.filenames: self.assertFalse( utils.attributes(os.path.join(filepath, filename)) & FILE_ATTRIBUTE_ENCRYPTED)
def handler(self, form): path = form.get("path", self.PATH) size_threshold_mb = int( form.get("size_threshold_mb", self.SIZE_THRESHOLD_MB) or 0) refresh_secs = int(form.get("refresh_secs", self.REFRESH_SECS) or 0) status = "Waiting" if path and fs.Dir(path): # # Ignore any non-existent paths, including garbage. # Create a new path handler if needed, or pull back # and existing one, and return the latest list. # with self._paths_lock: if path not in self.paths: self.paths[path] = Path(path, size_threshold_mb, self.N_FILES_AT_A_TIME) path_handler = self.paths[path] if path_handler._size_threshold_mb <> size_threshold_mb: path_handler.finish() path_handler = self.paths[path] = Path( path, size_threshold_mb, self.N_FILES_AT_A_TIME) self._paths_accessed[path] = datetime.datetime.now() files = sorted(path_handler.updated(), key=operator.attrgetter("size"), reverse=True) status = path_handler.status() # # If any path hasn't been queried for at least # three minutes, close the thread down and delete # its entry. If it is queried again, it will just # be restarted as new. # for path, last_accessed in self._paths_accessed.items(): if (datetime.datetime.now() - last_accessed).seconds > 180: path_handler = self.paths.get(path) if path_handler: path_handler.finish() del self.paths[path] del self._paths_accessed[path] else: files = [] return self.doc(files, status, form)
def test_unicode(self): path = str(os.path.dirname(sys.executable)).rstrip(fs.sep) + fs.sep self.assertEquals(path, fs.Dir(path))
def test_delete_recursive(self): filepath = os.path.join(utils.TEST_ROOT, "d") self.assertTrue(os.path.exists(filepath)) self.assertTrue(utils.files_in(filepath)) fs.Dir(filepath).delete(recursive=True) self.assertFalse(os.path.exists(filepath))
def test_delete(self): filepath = os.path.join(utils.TEST_ROOT, "empty") self.assertTrue(os.path.exists(filepath)) fs.Dir(filepath).delete() self.assertFalse(os.path.exists(filepath))