`
gumuzhiyu
  • 浏览: 35611 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

python test1

 
阅读更多
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys, os, stat
import argparse

# -b
def isBlockfile(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    if stat.S_ISBLK(mode):
        return 0
    else:
        return 1
# -c
def isCharspecial(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    if stat.S_ISCHR(mode):
        return 0
    else:
        return 1
# -d
def isDirectory(x, y):
    if os.path.isdir(x):
        return 0
    else:
        return 1    
# -e
def isExists(x,y):
    if os.path.exists(x):
        return 0
    else:
        return 1
# -f
def isFile(x, y):
    if os.path.isfile(x):
        return 0
    else:
        return 1    
# -g
def issetGroupID(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    tmode = stat.S_IMODE(os.lstat(st)[stat.ST_MODE])
    if tmode & getattr(stat, "S_ISGID"):
        return 0
    else:
        return 1    
# -G
def isownGroupID(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    groups = os.getgroups()
    if stf.st_gid in groups:
        return 0
    else:
        return 1 

# -h
# -k
def isStickyBit(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    kmode = stat.S_IMODE(os.lstat(st)[stat.ST_MODE])
    if kmode & getattr(stat, "S_ISVTX"):
        return 0
    else:
        return 1

# -L
def isLink(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    if stat.S_ISLNK(mode):
        return 0
    else:
        return 1
# -O
def isownUserID(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    uid = os.stat(st).st_uid
    if None != uid:
        return 0
    else:
        return 1
# -p
def isnamePipe(x, y):
    # FILE exists and is a named pipe
    stf = os.stat(x)
    mode = stf.st_mode
    if stat.S_ISFIFO(mode):
        return 0
    else:
        return 1    

# -r
def isRead(x, y):
    if os.access(x, os.R_OK):
        return 0
    else:
        return 1    
# -s
# -S
def isSocket(x, y):
    # FILE exists and is a socket
    stf = os.stat(x)
    mode = stf.st_mode
    if stat.S_ISSOCK(mode):
        return 0
    else:
        return 1    

# -t
# -u
def issetUserID(x, y):
    stf = os.stat(x)
    mode = stf.st_mode
    umode = stat.S_IMODE(os.lstat(st)[stat.ST_MODE])
    if umode & getattr(stat, "S_ISUID"):
        return 0
    else:
        return 1    
# -w
def isWriter(x, y):
    if os.access(x, os.W_OK):
        return 0
    else:
        return 1   
# -x
def isExecute(x, y):
    if os.access(x, os.X_OK):
        return 0
    else:
        return 1
# -z
def isZero(x, y):
    if len(x) = 0:
        return 0
    else:
        return 1
# -n
def isNonZero(x, y):
    if len(x) != 0:
        return 0
    else:
        return 1


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics