コード例 #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
コード例 #2
0
ファイル: file.py プロジェクト: Hong-Xiang/dxl
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
コード例 #3
0
ファイル: file.py プロジェクト: Hong-Xiang/dxl
 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)
コード例 #4
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def test_glob(self):
     result = fs.Directory.glob(Path(self.root + '/sub6'))
     assert set(result) == {
         self.root + '/sub6/sub7', self.root + '/sub6/test.txt'
     }
コード例 #5
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def test_delete_directory(self):
     path = Path(self.root + '/sub2')
     fs.Directory.delete(path)
     assert not fs.exists(path)
コード例 #6
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 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'))
コード例 #7
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def test_create_directory(self):
     path = Path(self.root + '/sub3')
     fs.Directory.create(path)
     assert fs.exists(path)
コード例 #8
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def test_create_file(self):
     path = Path(self.root + '/tmp3.txt')
     fs.File.create(path)
     assert fs.exists(path)
コード例 #9
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def neg():
     file1 = str((pathlib.Path(self.root) / 'tmpx.txt').absolute())
     assert not fs.exists(Path(file1))
コード例 #10
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 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'))
コード例 #11
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def pos():
     file1 = str((pathlib.Path(self.root) / 'tmp.txt').absolute())
     assert fs.exists(Path(file1))
コード例 #12
0
ファイル: file_system.py プロジェクト: Hong-Xiang/dxl
 def exists(path):
     if isinstance(path, str):
         path = Path(path)
     return pathlib.Path(path.abs).exists()
コード例 #13
0
ファイル: file_system.py プロジェクト: Hong-Xiang/dxl
 def create(path, parents=False):
     if isinstance(path, str):
         path = Path(path)
     return pathlib.Path(path.abs).mkdir(parents=parents)
コード例 #14
0
ファイル: file.py プロジェクト: Hong-Xiang/dxl
 def check(path, file_system):
     if isinstance(path, str):
         path = Path(path)
     return file_system.exists(path)
コード例 #15
0
ファイル: test_file_system.py プロジェクト: Hong-Xiang/dxl
 def test_delete_file(self):
     path = Path(self.root + '/tmp2.txt')
     fs.File.delete(path)
     assert not fs.exists(path)
コード例 #16
0
ファイル: file.py プロジェクト: Hong-Xiang/dxl
 def check(path, file_system):
     if isinstance(path, str):
         path = Path(path)
     return file_system.Directory.check(path)
コード例 #17
0
 def __init__(self, workdir=None, duration=5):
     self.workdir = Path(workdir)
     self.duration = duration