Exemple #1
0
 def __init__(self,
              tid=None,
              desc='',
              workdir='.',
              worker=None,
              ttype=None,
              state=None,
              time_stamp=None,
              dependency=None,
              is_root=True,
              data=None):
     self.id = tid
     self.desc = desc
     self.workdir = Path(workdir).abs
     if worker is None:
         worker = Worker.NoAction
     self.worker = worker
     if time_stamp is None:
         time_stamp = TaskStamp.create_now()
     self.time_stamp = time_stamp
     if dependency is None:
         dependency = []
     self.dependency = dependency
     if ttype is None:
         ttype = Type.Regular
     self.type = ttype
     if state is None:
         state = State.BeforeSubmit
     self.state = state
     self.is_root = is_root
     if data is None:
         data = {}
     self.data = data
Exemple #2
0
class FileAbstract(metaclass=ABCMeta):
    """ File class focus on existance.
    """
    def __init__(self, path, file_system):
        self.path = Path(path)
        self.fs = file_system
        if not self.check(self.path, self.fs):
            raise FileNotFoundOrWrongTypeError(self.path, self.ftype)

    @staticmethod
    def check(path, file_system):
        if isinstance(path, str):
            path = Path(path)
        return file_system.exists(path)

    def copy_to(self, path):
        result = self.fs.copy(path, self.path)
        return result

    def move_to(self, path):
        result = self.fs.move(path, self.path)
        return result

    @abstractmethod
    def update(self, content):
        return NotImplementedError

    @abstractmethod
    def delete(self):
        raise NotImplementedError

    @property
    def ftype(self):
        return {'FileAbstract'}

    @property
    def brief(self):
        """ A JSON serilizable info dict.
        """
        types = [str(x) for x in self.ftype]
        types.sort()
        return {'path': self.path.abs, 'name': self.path.name, 'type': types}

    @property
    def detail(self):
        result = self.brief
        result.update({
            'parent': self.path.parent,
            'parts': self.path.parts(),
        })
        return result
Exemple #3
0
 def __init__(self, path, file_system):
     self.path = Path(path)
     self.fs = file_system
     if not self.check(self.path, self.fs):
         raise FileNotFoundOrWrongTypeError(self.path, self.ftype)
Exemple #4
0
 def test_glob(self):
     result = fs.Directory.glob(Path(self.root + '/sub6'))
     assert set(result) == {
         self.root + '/sub6/sub7', self.root + '/sub6/test.txt'
     }
Exemple #5
0
 def test_delete_directory(self):
     path = Path(self.root + '/sub2')
     fs.Directory.delete(path)
     assert not fs.exists(path)
Exemple #6
0
 def test_is_dir(self):
     assert fs.Directory.check(Path(self.root + '/sub1'))
     assert not fs.Directory.check(Path(self.root + '/subx'))
     assert not fs.Directory.check(Path(self.root + '/tmp.txt'))
Exemple #7
0
 def test_create_directory(self):
     path = Path(self.root + '/sub3')
     fs.Directory.create(path)
     assert fs.exists(path)
Exemple #8
0
 def test_create_file(self):
     path = Path(self.root + '/tmp3.txt')
     fs.File.create(path)
     assert fs.exists(path)
Exemple #9
0
 def neg():
     file1 = str((pathlib.Path(self.root) / 'tmpx.txt').absolute())
     assert not fs.exists(Path(file1))
Exemple #10
0
 def test_is_file(self):
     assert fs.File.check(Path(self.root + '/tmp.txt'))
     assert not fs.File.check(Path(self.root + '/tmpx.txt'))
     assert not fs.File.check(Path(self.root + '/sub1'))
Exemple #11
0
 def pos():
     file1 = str((pathlib.Path(self.root) / 'tmp.txt').absolute())
     assert fs.exists(Path(file1))
Exemple #12
0
 def exists(path):
     if isinstance(path, str):
         path = Path(path)
     return pathlib.Path(path.abs).exists()
Exemple #13
0
 def create(path, parents=False):
     if isinstance(path, str):
         path = Path(path)
     return pathlib.Path(path.abs).mkdir(parents=parents)
Exemple #14
0
 def check(path, file_system):
     if isinstance(path, str):
         path = Path(path)
     return file_system.exists(path)
Exemple #15
0
 def test_delete_file(self):
     path = Path(self.root + '/tmp2.txt')
     fs.File.delete(path)
     assert not fs.exists(path)
Exemple #16
0
 def check(path, file_system):
     if isinstance(path, str):
         path = Path(path)
     return file_system.Directory.check(path)
Exemple #17
0
 def __init__(self, workdir=None, duration=5):
     self.workdir = Path(workdir)
     self.duration = duration