コード例 #1
0
def mkstemp_rename(destination,  **kwargs):
    """For writing to a temporary file and then move it ontop of a
    (possibly) existing file only when finished.  This enables us to
    perform long running operations on a file that other people might
    be using and let everyone else see a consistent version.

    * other args are passed to tempfile.mkstemp

    Example::

        with mkstemp_rename('foobar.txt') as f:
            f.write('stuff\n')

    """
    log = kwargs.pop('log', None)
    kwargs.setdefault('dir', os.path.dirname(destination))

    (fd, path) = tempfile.mkstemp(**kwargs)
    path = Path(path)
    try:
        filelike = os.fdopen(fd, 'wb')
        yield filelike
        filelike.close()
        path.chmod(0o0644)
        path.rename(destination)
    finally:
        path.remove_p()
コード例 #2
0
ファイル: utils.py プロジェクト: aritu/nuxeo-drive
def set_path_readonly(path: Path) -> None:
    if path.is_dir():
        # Need to add
        right = stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IRUSR
    else:
        # Already in read only
        right = stat.S_IRGRP | stat.S_IRUSR

    if path.stat().st_mode & ~right != 0:
        path.chmod(right)
コード例 #3
0
ファイル: utils.py プロジェクト: nuxeo/nuxeo-drive
def set_path_readonly(path: Path) -> None:
    if path.is_dir():
        # Need to add
        right = stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IRUSR
    else:
        # Already in read only
        right = stat.S_IRGRP | stat.S_IRUSR

    if path.stat().st_mode & ~right != 0:
        path.chmod(right)
コード例 #4
0
ファイル: plugin.py プロジェクト: OpenAZBox/RTi-Old
 def doCHMod(self, chmod):
     if chmod:
         chmod = int(str(chmod), 10)
         if chmod > 777:
             chmod == 777
         
         if chmod < 0:
             chmod == 0
         
         os.chmod(self.pateka, int(str(chmod), 8))
         self.close()
コード例 #5
0
ファイル: utils.py プロジェクト: aritu/nuxeo-drive
def unset_path_readonly(path: Path) -> None:
    if path.is_dir():
        right = (stat.S_IXUSR
                 | stat.S_IRGRP
                 | stat.S_IXGRP
                 | stat.S_IRUSR
                 | stat.S_IWGRP
                 | stat.S_IWUSR)
    else:
        right = stat.S_IRGRP | stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR

    if path.stat().st_mode & right != right:
        path.chmod(right)
コード例 #6
0
ファイル: utils.py プロジェクト: nuxeo/nuxeo-drive
def unset_path_readonly(path: Path) -> None:
    if path.is_dir():
        right = (
            stat.S_IXUSR
            | stat.S_IRGRP
            | stat.S_IXGRP
            | stat.S_IRUSR
            | stat.S_IWGRP
            | stat.S_IWUSR
        )
    else:
        right = stat.S_IRGRP | stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR

    if path.stat().st_mode & right != right:
        path.chmod(right)
コード例 #7
0
ファイル: plugin.py プロジェクト: OpenAZBox/RTi-Old
 def doCHMod(self, chmod):
     if chmod:
         if os.path.isdir(self.SOURCELIST.getFilename()) == True:
             pattern = self.SOURCELIST.getFilename()
         else:
             pattern = self.SOURCELIST.getCurrentDirectory() + self.SOURCELIST.getFilename()
         chmod = int(str(chmod), 10)
         if chmod > 777:
             chmod == 777
         
         if chmod < 0:
             chmod == 0
         
         os.chmod(pattern, int(str(chmod), 8))
         self.GetCHMod()
コード例 #8
0
ファイル: hooks_test.py プロジェクト: ZhangNatural/vdsm
def file_entry_apply(self, hooks_dir):
    path = hooks_dir.join(self.name)
    path.write(self.contents)
    path.chmod(self.mode)
コード例 #9
0
ファイル: hooks_test.py プロジェクト: ZhangNatural/vdsm
def dir_entry_apply(self, hooks_dir):
    path = hooks_dir.join(self.name)
    path.mkdir()
    for entry in self.contents:
        entry.apply(path)
    path.chmod(self.mode)