예제 #1
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __write(self, lines):
     try:
         with open(self.path, 'w') as fd:
             for line in lines:
                 fd.write(str(line) + '\n')
     except EnvironmentError as e:
         # should never happen
         raise cinv.Error(str(e))
예제 #2
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __setitem__(self, key, value):
     try:
         with open(os.path.join(self.path, key), "w") as fd:
             if type(value) == type([]):
                 for v in value:
                     fd.write(str(v) + '\n')
             else:
                 fd.write(str(value) + '\n')
     except EnvironmentError as e:
         raise cinv.Error(str(e))
예제 #3
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __set__(self, instance, value):
     path = self._get_path(instance)
     if value:
         try:
             with open(path, "w") as fd:
                 fd.write("%s\n" % str(value))
         except EnvironmentError as e:
             raise cinv.Error(str(e))
     else:
         try:
             os.remove(path)
         except EnvironmentError:
             pass
예제 #4
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __set__(self, instance, value):
     path = self._get_path(instance)
     if value:
         try:
             open(path, "w").close()
         except EnvironmentError as e:
             raise cinv.Error(str(e))
     else:
         try:
             os.remove(path)
         except EnvironmentError:
             # ignore
             pass
예제 #5
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __init__(self, path, initial=None, **kwargs):
     if not os.path.isabs(path):
         raise AbsolutePathRequiredError(path)
     self.path = path
     try:
         # create directory if it doesn't exist
         if not os.path.isdir(self.path):
             os.mkdir(self.path)
     except EnvironmentError as e:
         raise cinv.Error(str(e))
     if initial is not None:
         self.update(initial)
     if kwargs:
         self.update(kwargs)
예제 #6
0
파일: fsproperty.py 프로젝트: bhyvex/cinv
 def __len__(self):
     try:
         return len(os.listdir(self.path))
     except EnvironmentError as e:
         raise cinv.Error(str(e))