FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 06-01-2011, 01:18 PM
Martin Gracik
 
Default Improvements to mknod-stub

Related: rhbz#706099
---
command-stubs/mknod-stub | 73 ++++++++++++++++++++++++++++-----------------
1 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/command-stubs/mknod-stub b/command-stubs/mknod-stub
index dd72aeb..8344a08 100755
--- a/command-stubs/mknod-stub
+++ b/command-stubs/mknod-stub
@@ -2,7 +2,7 @@
#
# mknod-stub
#
-# Copyright (C) 2007 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2007, 2011 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,41 +18,58 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

-import sys, os
-sys.path.append('/usr/lib/anaconda')
-import isys
-import string
-import stat
+from optparse import OptionParser
import os
+import stat
+import sys
+

def usage():
- sys.stderr.write("Usage: %s <path> [b|c] <major> <minor>
" %(sys.argv[0],))
- sys.exit(1)
+ return 'Usage: %prog <path> [b|c] <major> <minor>'
+
+
+def main(prog, args):
+
+ def err(msg):
+ sys.stderr.write('%s: %s
' % (os.path.basename(prog), msg))
+ sys.exit(1)
+
+ DEVTYPES = { 'b' : stat.S_IFBLK,
+ 'c' : stat.S_IFCHR }
+
+ DEVMODE = 0644

-def main():
- if len(sys.argv) < 2:
- usage()
+ parser = OptionParser(usage=usage())
+ opts, args = parser.parse_args(args)

- if (sys.argv[1] == '-h') or (sys.argv[1] == '--help'):
- usage()
+ try:
+ path, devtype, major, minor = args
+ except ValueError:
+ if len(args) > 4:
+ err("extra operand '%s'" % args[4])
+ else:
+ err('missing operand')

- path = sys.argv[1]
+ try:
+ devtype = DEVTYPES[devtype]
+ except KeyError:
+ err("invalid device type '%s'" % devtype)

- if len(sys.argv) < 5:
- usage()
+ try:
+ major = int(major)
+ except ValueError:
+ err("invalid major device number '%s'" % major)

- if (sys.argv[2] == 'b'):
- type = stat.S_IFBLK
- elif (sys.argv[2] == 'c'):
- type = stat.S_IFCHR
- else:
- usage()
+ try:
+ minor = int(minor)
+ except ValueError:
+ err("invalid minor device number '%s'" % minor)

- major = int(sys.argv[3])
- minor = int(sys.argv[4])
- path = sys.argv[1]
+ try:
+ os.mknod(path, DEVMODE | devtype, os.makedev(major, minor))
+ except OSError as e:
+ err(e)

- os.mknod(path, 0644 | type, os.makedev(major, minor))

-if __name__ == "__main__":
- main()
+if __name__ == '__main__':
+ main(prog=sys.argv[0], args=sys.argv[1:])
--
1.7.3.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 04:15 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org