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
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
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
 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
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
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
 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
def file_entry_apply(self, hooks_dir):
    path = hooks_dir.join(self.name)
    path.write(self.contents)
    path.chmod(self.mode)
Пример #9
0
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)