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 losetup-stub

Related: rhbz#706099
---
command-stubs/losetup-stub | 74 ++++++++++++++++++++++++++------------------
1 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/command-stubs/losetup-stub b/command-stubs/losetup-stub
index bf186a1..af9bd51 100755
--- a/command-stubs/losetup-stub
+++ b/command-stubs/losetup-stub
@@ -2,7 +2,7 @@
#
# losetup-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,39 +18,53 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

+from optparse import OptionParser
import os
import sys

-# for testing
-if (os.path.exists('isys')):
- sys.path.append('isys')
-
sys.path.append('/usr/lib/anaconda')
-
import isys
-from sys import argv
+

def usage():
- print "usage: losetup [-d] /dev/loopN [image]"
- sys.exit(1)
-
-if len(argv) < 3:
- usage()
-
-if argv[1] == "-d" and len(argv[2]) > 4 and argv[2][-5:-1] == "loop":
- try:
- isys.unlosetup(argv[2])
- except SystemError, (errno, msg):
- print msg
- sys.exit (1)
- sys.exit(0)
-
-if len(argv[1]) > 4 and argv[1][-5:-1] == "loop":
- try:
- isys.losetup(argv[1], argv[2])
- except SystemError, (errno, msg):
- print msg
- sys.exit (1)
- sys.exit(0)
-
-usage()
+ return 'Usage: %prog [-d] <loopdev> [file]'
+
+
+def main(prog, args):
+
+ def err(msg):
+ sys.stderr.write('%s: %s
' % (os.path.basename(prog), msg))
+ sys.exit(1)
+
+ parser = OptionParser(usage=usage())
+ parser.add_option('-d', '--detach', action='store_true', default=False)
+
+ opts, args = parser.parse_args(args)
+
+ if opts.detach:
+ if not args:
+ err('missing operand')
+
+ for loopdev in args:
+ try:
+ isys.unlosetup(loopdev)
+ except SystemError as e:
+ err(e)
+
+ else:
+ try:
+ loopdev, image = args
+ except ValueError:
+ if len(args) > 2:
+ err("extra operand '%s'" % args[2])
+ else:
+ err('missing operand')
+ else:
+ try:
+ isys.losetup(loopdev, image)
+ except SystemError as e:
+ err(e)
+
+
+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 08:04 AM.

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