コード例 #1
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_create_already_exists_not_dir (self):
   with self.assertRaises (fs.x_fs):
     #
     # If the name is already used by a file, create will raise x_fs
     #
     filepath = os.path.join (utils.TEST_ROOT, uuid.uuid1 ().hex)
     open (filepath, "w").close ()
     self.assertTrue (os.path.isfile (filepath))
     fs.dir (filepath).create ()
コード例 #2
0
 def test_create_already_exists_not_dir(self):
     with self.assertRaises(fs.x_fs):
         #
         # If the name is already used by a file, create will raise x_fs
         #
         filepath = os.path.join(utils.TEST_ROOT, uuid.uuid1().hex)
         open(filepath, "w").close()
         self.assertTrue(os.path.isfile(filepath))
         fs.dir(filepath).create()
コード例 #3
0
 def test_flat_with_dirs(self):
     filepath = utils.TEST_ROOT
     filepath2 = os.path.join(filepath, "d")
     self.assertEquals(
         set(fs.dir(filepath).flat(includedirs=True)),
         utils.dirs_in(filepath) | utils.files_in(filepath)
         | utils.dirs_in(filepath2) | utils.files_in(filepath2))
コード例 #4
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_flat_with_dirs (self):
   filepath = utils.TEST_ROOT
   filepath2 = os.path.join (filepath, "d")
   self.assertEquals (
     set (fs.dir (filepath).flat (includedirs=True)),
     utils.dirs_in (filepath) | utils.files_in (filepath) | utils.dirs_in (filepath2) | utils.files_in (filepath2)
   )
コード例 #5
0
 def test_create_already_exists_dir(self):
     #
     # If the dir already exists, create will succeed silently
     # and will return the normalised path of the dir.
     #
     filepath = os.path.join(utils.TEST_ROOT, uuid.uuid1().hex)
     os.mkdir(filepath)
     self.assertTrue(os.path.isdir(filepath))
     d = fs.dir(filepath)
     self.assertEquals(fs.normalised(d), fs.normalised(d.create()))
コード例 #6
0
def searcher(root, pattern, text):
    for dir, dirs, files in fs.dir(root).walk(ignore_access_errors=True):
        yield dir.filepath
        for f in files:
            if f.like(pattern):
                try:
                    if text in open(f.filepath).read():
                        files_found.append(f)
                except fs.exc.x_access_denied:
                    pass
コード例 #7
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_create_already_exists_dir (self):
   #
   # If the dir already exists, create will succeed silently
   # and will return the normalised path of the dir.
   #
   filepath = os.path.join (utils.TEST_ROOT, uuid.uuid1 ().hex)
   os.mkdir (filepath)
   self.assertTrue (os.path.isdir (filepath))
   d = fs.dir (filepath)
   self.assertEquals (fs.normalised (d), fs.normalised (d.create ()))
コード例 #8
0
def searcher (root, pattern, text):
  for dir, dirs, files in fs.dir (root).walk (ignore_access_errors=True):
    yield dir.filepath
    for f in files:
      if f.like (pattern):
        try:
          if text in open (f.filepath).read ():
            files_found.append (f)
        except fs.exc.x_access_denied:
          pass
コード例 #9
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_zip (self):
   import zipfile
   filepath = utils.TEST_ROOT
   zipped = fs.dir (filepath).zip ()
   unzip_filepath = os.path.join (utils.TEST_ROOT2)
   os.mkdir (unzip_filepath)
   zipfile.ZipFile (zipped).extractall (unzip_filepath)
   self.assertEquals (
     set (f.relative_to (filepath) for f in fs.flat (filepath)),
     set (f.relative_to (unzip_filepath) for f in fs.flat (unzip_filepath))
   )
コード例 #10
0
 def test_zip(self):
     import zipfile
     filepath = utils.TEST_ROOT
     zipped = fs.dir(filepath).zip()
     unzip_filepath = os.path.join(utils.TEST_ROOT2)
     os.mkdir(unzip_filepath)
     zipfile.ZipFile(zipped).extractall(unzip_filepath)
     self.assertEquals(
         set(f.relative_to(filepath) for f in fs.flat(filepath)),
         set(
             f.relative_to(unzip_filepath)
             for f in fs.flat(unzip_filepath)))
コード例 #11
0
    def test_walk(self):
        filepath = utils.TEST_ROOT
        walker = fs.dir(filepath).walk()
        dirpath, dirs, files = next(walker)
        self.assertEquals(dirpath, filepath + "\\")
        self.assertEquals(set(dirs), utils.dirs_in(filepath))
        self.assertEquals(set(files), utils.files_in(filepath))

        filepath = os.path.join(filepath, "d")
        dirpath, dirs, files = next(walker)
        self.assertEquals(dirpath, filepath + "\\")
        self.assertEquals(set(dirs), utils.dirs_in(filepath))
        self.assertEquals(set(files), utils.files_in(filepath))
コード例 #12
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
  def test_walk (self):
    filepath = utils.TEST_ROOT
    walker = fs.dir (filepath).walk ()
    dirpath, dirs, files = next (walker)
    self.assertEquals (dirpath, filepath + "\\")
    self.assertEquals (set (dirs), utils.dirs_in (filepath))
    self.assertEquals (set (files), utils.files_in (filepath))

    filepath = os.path.join (filepath, "d")
    dirpath, dirs, files = next (walker)
    self.assertEquals (dirpath, filepath + "\\")
    self.assertEquals (set (dirs), utils.dirs_in (filepath))
    self.assertEquals (set (files), utils.files_in (filepath))
コード例 #13
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
  def test_watch (self):
    filepath = utils.TEST_ROOT
    removed_filename = os.path.join (filepath, "1")
    added_filename = os.path.join (filepath, uuid.uuid1 ().hex)
    old_filename = os.path.join (filepath, "2")
    new_filename = os.path.join (filepath, uuid.uuid1 ().hex)
    def _change_dir ():
      os.remove (removed_filename)
      open (added_filename, "w").close ()
      os.rename (old_filename, new_filename)

    watcher = fs.dir (filepath).watch ()
    t = threading.Timer (0.5, _change_dir)
    t.start ()
    self.assertEquals (next (watcher), (fs.FILE_ACTION.REMOVED, removed_filename, None))
    self.assertEquals (next (watcher), (fs.FILE_ACTION.ADDED, None, added_filename))
    self.assertEquals (next (watcher), (fs.FILE_ACTION.RENAMED_NEW_NAME, old_filename, new_filename))
    t.join ()
コード例 #14
0
ファイル: monitor_directory.py プロジェクト: one2pret/winsys
def get_files (path, size_threshold_mb, results, stop_event):
  """Intended to run inside a thread: scan the contents of
  a tree recursively, pushing every file which is at least
  as big as the size threshold onto a results queue. Stop
  if the stop_event is set.
  """
  size_threshold = size_threshold_mb * 1024 * 1024
  root = fs.dir (path)
  top_level_folders = sorted (root.dirs (), key=operator.attrgetter ("written_at"), reverse=True)
  try:
    for tlf in top_level_folders:
      for f in tlf.flat (ignore_access_errors=True):
        if stop_event.isSet ():
          print "stop event set"
          raise x_stop_exception
        try:
          if f.size > size_threshold:
            results.put (f)
        except fs.exc.x_winsys:
          continue
  except x_stop_exception:
    return
コード例 #15
0
    def test_watch(self):
        filepath = utils.TEST_ROOT
        removed_filename = os.path.join(filepath, "1")
        added_filename = os.path.join(filepath, uuid.uuid1().hex)
        old_filename = os.path.join(filepath, "2")
        new_filename = os.path.join(filepath, uuid.uuid1().hex)

        def _change_dir():
            os.remove(removed_filename)
            open(added_filename, "w").close()
            os.rename(old_filename, new_filename)

        watcher = fs.dir(filepath).watch()
        t = threading.Timer(0.5, _change_dir)
        t.start()
        self.assertEquals(next(watcher),
                          (fs.FILE_ACTION.REMOVED, removed_filename, None))
        self.assertEquals(next(watcher),
                          (fs.FILE_ACTION.ADDED, None, added_filename))
        self.assertEquals(
            next(watcher),
            (fs.FILE_ACTION.RENAMED_NEW_NAME, old_filename, new_filename))
        t.join()
コード例 #16
0
ファイル: monitor_directory.py プロジェクト: szlaci83/winsys
def get_files(path, size_threshold_mb, results, stop_event):
    """Intended to run inside a thread: scan the contents of
    a tree recursively, pushing every file which is at least
    as big as the size threshold onto a results queue. Stop
    if the stop_event is set.
    """
    size_threshold = size_threshold_mb * 1024 * 1024
    root = fs.dir(path)
    top_level_folders = sorted(root.dirs(),
                               key=operator.attrgetter("written_at"),
                               reverse=True)
    try:
        for tlf in top_level_folders:
            for f in tlf.flat(ignore_access_errors=True):
                if stop_event.isSet():
                    print("stop event set")
                    raise x_stop_exception
                try:
                    if f.size > size_threshold:
                        results.put(f)
                except fs.exc.x_winsys:
                    continue
    except x_stop_exception:
        return
コード例 #17
0
ファイル: get_access.py プロジェクト: one2pret/winsys
from winsys import fs, security

full_control = security.ace ((security.me (), "F", "ALLOW"))

def take_control (f):
  f.take_ownership ()
  with f.security () as s:
    s.dacl.append (full_control)

start_from = fs.dir (raw_input ("Start from: "))
take_control (start_from)
for f in start_from.flat (includedirs=True):
  print f
  take_control (f)
コード例 #18
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_create (self):
   filepath = os.path.join (utils.TEST_ROOT, uuid.uuid1 ().hex)
   self.assertFalse (os.path.exists (filepath))
   fs.dir (filepath).create ()
   self.assertTrue (os.path.exists (filepath))
   self.assertTrue (os.path.isdir (filepath))
コード例 #19
0
ファイル: test_fs.py プロジェクト: hashar/WAPT
def test_DriveRoot():
  assert fs.Drive("C:").root() == fs.dir (u"C:\\")
コード例 #20
0
ファイル: test_drive.py プロジェクト: Azure8705/winsys
 def test_DriveRoot (self):
   self.assertEquals (fs.drive ("C:").root, fs.dir ("C:\\"))
コード例 #21
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_dirs (self):
   filepath = utils.TEST_ROOT
   self.assertEquals (
     set (fs.dir (filepath).dirs ()),
     utils.dirs_in (filepath)
   )
コード例 #22
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_file (self):
   filepath = utils.TEST_ROOT
   self.assertEquals (fs.dir (filepath).file ("1"), os.path.join (filepath, "1"))
コード例 #23
0
 def test_dirs(self):
     filepath = utils.TEST_ROOT
     self.assertEquals(set(fs.dir(filepath).dirs()),
                       utils.dirs_in(filepath))
コード例 #24
0
ファイル: shell.py プロジェクト: Azure8705/winsys
 def _get_working_directory(self):
     return fs.dir(self._shell_link.GetWorkingDirectory())
コード例 #25
0
 def test_entries(self):
     filepath = utils.TEST_ROOT
     self.assertEquals(set(fs.dir(filepath).entries()),
                       utils.files_in(filepath) | utils.dirs_in(filepath))
コード例 #26
0
 def _get_working_directory(self):
     return fs.dir(self._shell_link.GetWorkingDirectory())
コード例 #27
0
ファイル: find_dir_sizes.py プロジェクト: Azure8705/winsys
import operator
from winsys import dialogs, fs, utils

[root] = dialogs.dialog(
    "Find top-level sizes",
    ("Start from", "", dialogs.get_folder)
)

sizes = dict(
   (d, sum(f.size for f in d.flat()))
        for d in fs.dir(root).dirs()
)
for d, size in sorted(sizes.items(), key=operator.itemgetter(1), reverse=True):
    print d.name, "=>", utils.size_as_mb(size)
コード例 #28
0
 def test_create(self):
     filepath = os.path.join(utils.TEST_ROOT, uuid.uuid1().hex)
     self.assertFalse(os.path.exists(filepath))
     fs.dir(filepath).create()
     self.assertTrue(os.path.exists(filepath))
     self.assertTrue(os.path.isdir(filepath))
コード例 #29
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_entries (self):
   filepath = utils.TEST_ROOT
   self.assertEquals (
     set (fs.dir (filepath).entries ()),
     utils.files_in (filepath) | utils.dirs_in (filepath)
   )
コード例 #30
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_flat (self):
   filepath = utils.TEST_ROOT
   self.assertEquals (
     set (fs.dir (filepath).flat ()),
     utils.files_in (filepath) | utils.files_in (os.path.join (filepath, "d"))
   )
コード例 #31
0
ファイル: test_dir.py プロジェクト: one2pret/winsys
 def test_dir (self):
   filepath = utils.TEST_ROOT
   self.assertEquals (fs.dir (filepath).dir ("d"), os.path.join (filepath, "d\\"))
コード例 #32
0
ファイル: test_fs.py プロジェクト: ssamson-tis/WAPT
def test_DriveRoot():
    assert fs.Drive("C:").root() == fs.dir(u"C:\\")
コード例 #33
0
 def test_flat(self):
     filepath = utils.TEST_ROOT
     self.assertEquals(
         set(fs.dir(filepath).flat()),
         utils.files_in(filepath)
         | utils.files_in(os.path.join(filepath, "d")))
コード例 #34
0
ファイル: test_drive.py プロジェクト: szlaci83/winsys
 def test_DriveRoot(self):
     self.assertEquals(fs.drive("C:").root, fs.dir("C:\\"))
コード例 #35
0
 def test_file(self):
     filepath = utils.TEST_ROOT
     self.assertEquals(
         fs.dir(filepath).file("1"), os.path.join(filepath, "1"))
コード例 #36
0
from winsys import fs, security

full_control = security.ace((security.me(), "F", "ALLOW"))


def take_control(f):
    f.take_ownership()
    with f.security() as s:
        s.dacl.append(full_control)


start_from = fs.dir(raw_input("Start from: "))
take_control(start_from)
for f in start_from.flat(includedirs=True):
    print f
    take_control(f)
コード例 #37
0
 def test_dir(self):
     filepath = utils.TEST_ROOT
     self.assertEquals(
         fs.dir(filepath).dir("d"), os.path.join(filepath, "d\\"))
コード例 #38
0
ファイル: find_dir_sizes.py プロジェクト: szlaci83/winsys
import operator
from winsys import dialogs, fs, utils

[root] = dialogs.dialog("Find top-level sizes",
                        ("Start from", "", dialogs.get_folder))

sizes = dict((d, sum(f.size for f in d.flat())) for d in fs.dir(root).dirs())
for d, size in sorted(sizes.items(), key=operator.itemgetter(1), reverse=True):
    print d.name, "=>", utils.size_as_mb(size)