我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用os.minor()。
def mounts(self, detectdev=False): mounts = [] with open('/proc/mounts', 'r') as f: for line in f: dev, path, fstype = line.split()[0:3] if fstype in ('ext2', 'ext3', 'ext4', 'xfs', 'jfs', 'reiserfs', 'btrfs', 'simfs'): # simfs: filesystem in OpenVZ if not os.path.isdir(path): continue mounts.append({'dev': dev, 'path': path, 'fstype': fstype}) for mount in mounts: stat = os.statvfs(mount['path']) total = stat.f_blocks*stat.f_bsize free = stat.f_bfree*stat.f_bsize used = (stat.f_blocks-stat.f_bfree)*stat.f_bsize mount['total'] = b2h(total) mount['free'] = b2h(free) mount['used'] = b2h(used) mount['used_rate'] = div_percent(used, total) if detectdev: dev = os.stat(mount['path']).st_dev mount['major'], mount['minor'] = os.major(dev), os.minor(dev) return mounts
def __init__(self, name=""): """Construct a TarInfo object. name is the optional name of the member. """ self.name = name # member name self.mode = 0644 # file permissions self.uid = 0 # user id self.gid = 0 # group id self.size = 0 # file size self.mtime = 0 # modification time self.chksum = 0 # header checksum self.type = REGTYPE # member type self.linkname = "" # link name self.uname = "" # user name self.gname = "" # group name self.devmajor = 0 # device major number self.devminor = 0 # device minor number self.offset = 0 # the tar header starts here self.offset_data = 0 # the file's data starts here self.pax_headers = {} # pax header information # In pax headers the "name" and "linkname" field are called # "path" and "linkpath".
def __init__(self, name=""): """Construct a CpioInfo object. name is the optional name of the member. """ self.ino = 0 # i-node self.mode = S_IFREG | 0o444 self.uid = 0 # user id self.gid = 0 # group id self.nlink = 1 # number of links self.mtime = 0 # modification time self.size = 0 # file size self.devmajor = 0 # device major number self.devminor = 0 # device minor number self.rdevmajor = 0 self.rdevminor = 0 self.namesize = 0 self.check = 0 self.name = name self.linkname = '' self.offset = 0 # the cpio header starts here self.offset_data = 0 # the file's data starts here self.buf = None
def lookup_device_name(major_number, minor_number): """ :param major_number: int. The major device number :param minor_number: int. The minor device number :return: string. The name of the device. Example: /dev/sda. Returns None on error. """ diskstats = get_disk_stats() for line in diskstats: parts = line.split() if not len(parts) > 3: # Skip bogus lines continue try: if int(parts[0]) is major_number and int(parts[1]) is \ minor_number: # Found our device. Return its name return parts[2] except ValueError as value_err: hookenv.log('Could not convert {} or {} into an integer. Error: {}' .format(parts[0], parts[1], str(value_err))) continue return None
def maj_min_to_blk(major, minor): """Returns the block device name to the major:minor numbers in the param. :param major: The major number of the device :param minor: The minor number of the device :returns: Block device name. :rtype: ``str`` """ maj_min = '{}:{}'.format(major, minor) block_dev = None for sys_path in glob.glob(os.path.join(os.sep, 'sys', 'class', 'block', '*', 'dev')): with io.open(sys_path) as f: if f.read().strip() == maj_min: block_dev = '/dev/{}'.format(sys_path.split(os.sep)[-2]) break return block_dev
def describe_entry(x): return """ Path: {x[path]} SHA: {hexsha} Size: {x[size]} Flags: {x[flags]:#b} User ID: {x[uid]} Group ID: {x[gid]} Created: {x[ctime]}.{x[ctime_nano]} Modified: {x[mtime]}.{x[mtime_nano]} Inode: {x[inode]} Device ID: ({major}, {minor}) """.format( x=x, major=os.major(x['dev']), minor=os.minor(x['dev']), hexsha=binascii.b2a_hex(x['sha']).decode('utf-8'), )
def __init__(self, name=""): """Construct a TarInfo object. name is the optional name of the member. """ self.name = name # member name self.mode = 0o644 # file permissions self.uid = 0 # user id self.gid = 0 # group id self.size = 0 # file size self.mtime = 0 # modification time self.chksum = 0 # header checksum self.type = REGTYPE # member type self.linkname = "" # link name self.uname = "" # user name self.gname = "" # group name self.devmajor = 0 # device major number self.devminor = 0 # device minor number self.offset = 0 # the tar header starts here self.offset_data = 0 # the file's data starts here self.sparse = None # sparse member information self.pax_headers = {} # pax header information # In pax headers the "name" and "linkname" field are called # "path" and "linkpath".
def storage_lazer(device): 'Returns the target device based on minor and major number' major = device['major'] minor = device['minor'] return sp.check_output('udevadm info -rq name /sys/dev/block/' + major + ':' + minor, shell=True).strip('\n') # STORAGE COMPOSED
def map_disk(DISK_TARGET, path): 'Creates a dictionary for LXD containing $path disk configuration, $DISK_TARGET will be $path \ inside the container' dev_stat = os.stat(path) major = str(os.major(dev_stat.st_rdev)) minor = str(os.minor(dev_stat.st_rdev)) return {DISK_TARGET: {'path': '/dev/' + DISK_TARGET, 'type': 'unix-block', 'minor': minor, 'major': major}}
def get_device_number(osd_number): """ This function will return a tuple of (major_number, minor_number) device number for the given osd. :param osd_number: int :rtype : (major_number,minor_number) """ path = "/var/lib/ceph/osd/ceph-{}".format(osd_number) info = os.lstat(path) major_number = os.major(info.st_dev) minor_number = os.minor(info.st_dev) return major_number, minor_number