Python stat.ST_UID Examples
The following are 8
code examples of stat.ST_UID().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stat
, or try the search function
.
Example #1
Source File: panel.py From coursys with GNU General Public License v3.0 | 6 votes |
def _check_cert(filename): """ Does this certificate file look okay? Returns error message, or None if okay """ try: st = os.stat(filename) except OSError: return filename + " doesn't exist" else: good_perm = stat.S_IFREG | stat.S_IRUSR # | stat.S_IWUSR if (st[stat.ST_UID], st[stat.ST_GID]) != (0,0): return 'not owned by root.root' perm = st[stat.ST_MODE] if good_perm != perm: return "expected permissions %o but found %o." % (good_perm, perm)
Example #2
Source File: init.py From server-bottle with GNU General Public License v2.0 | 6 votes |
def writable_by(dirname, name, user_or_group): """ Checks if the given directory is writable by the named user or group. user_or_group is a boolean with True for a user and False for a group. """ try: pwnam = pwd.getpwnam(name) except KeyError: print('[ERROR] User or group {0} does not exist!'.format(name)) return False ugid = pwnam.pw_uid if user_or_group else pwnam.pw_gid dir_stat = os.stat(dirname) ug_stat = dir_stat[stat.ST_UID] if user_or_group else dir_stat[stat.ST_GID] iw_stat = stat.S_IWUSR if user_or_group else stat.S_IWGRP if ((ug_stat == ugid) and (dir_stat[stat.ST_MODE] & iw_stat)): return True return False
Example #3
Source File: timecopy.py From timedog with GNU General Public License v2.0 | 6 votes |
def file(self, file): """Process a single file.""" dst = re.sub(self.src, self.dst, file) if self.verbose: print "cp <%s> <%s>" % (file, dst) if not self.dryrun: try: # Copy file contents from snapshot to destination. shutil.copyfile(file, dst) # Copy the permissions and accessed/modified times. shutil.copystat(file, dst) # Copy the owner/group values to destination. stats = os.lstat(file) chown(dst, stats[stat.ST_UID], stats[stat.ST_GID]) except IOError, e: print "ERROR '{}' processing file {}".format(e, file)
Example #4
Source File: io.py From locasploit with GNU General Public License v2.0 | 5 votes |
def get_file_info(system, path, verbose=False): fullpath = get_fullpath(system, path) if fullpath == IO_ERROR: return IO_ERROR result = {} if system.startswith('/'): # local or sub if can_read(system, path): # TODO platform-specific stats = os.stat(fullpath) stm = stats.st_mode result['type'] = get_file_type_char(stat.S_IFMT(stm)) result['permissions'] = '%o' % (stat.S_IMODE(stm)) result['UID'] = stats[stat.ST_UID] result['GID'] = stats[stat.ST_GID] result['ATIME'] = stats[stat.ST_ATIME] result['MTIME'] = stats[stat.ST_MTIME] result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO else: if verbose: log.info('File \'%s\' is not accessible.' % (fullpath)) result['type'] = None result['permissions'] = None result['UID'] = None result['GID'] = None result['ATIME'] = None result['MTIME'] = None result['CTIME'] = None return result else: # SSH/FTP/TFTP/HTTP # TODO NOT IMPLEMENTED return IO_ERROR
Example #5
Source File: timecopy.py From timedog with GNU General Public License v2.0 | 5 votes |
def dir(self, dir): """Create destination directory, copying stats and ownership.""" dst = re.sub(self.src, self.dst, dir) if self.verbose: print "mkdir <%s>" % dst if not self.dryrun: os.mkdir(dst) shutil.copystat(dir, dst) stats = os.lstat(dir) chown(dst, stats[stat.ST_UID], stats[stat.ST_GID]) if not self.dryrun or self.extattr: copyxattr(dir, dst) # Continue traversal... visitfiles(dir, self)
Example #6
Source File: timecopy.py From timedog with GNU General Public License v2.0 | 5 votes |
def link(self, link): """Copy link to destination.""" lnk = os.readlink(link) dst = re.sub(self.src, self.dst, link) if self.verbose: print "ln -s <%s> <%s>" % (lnk, dst) if not self.dryrun: os.symlink(lnk, dst) stats = os.lstat(link) chown(dst, stats[stat.ST_UID], stats[stat.ST_GID]) if not self.dryrun or self.extattr: copyxattr(link, dst)
Example #7
Source File: sourcetest.py From conary with Apache License 2.0 | 5 votes |
def __getitem__(self, item): if item == stat.ST_UID: return self.uid if item == stat.ST_GID: return self.gid return self.sb.__getitem__(item)
Example #8
Source File: base.py From stash with MIT License | 4 votes |
def calc_mode( sticky=False, isuid=True, isgid=True, type=stat.S_IFREG, owner_read=True, owner_write=True, owner_exec=True, group_read=True, group_write=True, group_exec=True, other_read=True, other_write=True, other_exec=True, ): """helper function to calculate the mode bits of a file.""" mode = 0 if owner_read: mode |= stat.S_IRUSR if owner_write: mode |= stat.S_IWUSR if owner_exec: mode |= stat.S_IXUSR if group_read: mode |= stat.S_IRGRP if group_write: mode |= stat.S_IWGRP if group_exec: mode |= stat.S_IXGRP if other_read: mode |= stat.S_IROTH if other_write: mode |= stat.S_IWOTH if other_exec: mode |= stat.S_IXOTH if sticky: mode |= stat.S_ISVTX if isuid: mode |= stat.ST_UID if isgid: mode |= stat.ST_GID mode |= type return mode