From 381026a7f6f511b8c7a3a696edb74fdf81730c48 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Wed, 6 Feb 2013 12:00:37 -0600 Subject: [PATCH 01/13] Add an example script which lists all devices. --- MANIFEST.in | 1 + examples/list_devices.py | 32 ++++++++++++++++++++++++++++++++ python-blivet.spec | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 examples/list_devices.py diff --git a/MANIFEST.in b/MANIFEST.in index 6ae6640..36972ba 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include COPYING ChangeLog Makefile python-blivet.spec recursive-include po *.po *.pot Makefile +recursive-include examples *.py diff --git a/examples/list_devices.py b/examples/list_devices.py new file mode 100644 index 0000000..8539ea1 --- /dev/null +++ b/examples/list_devices.py @@ -0,0 +1,32 @@ +import logging +import sys + +blivet_log = logging.getLogger("blivet") + +def set_up_logging(): + """ Configure the blivet logger to use /tmp/blivet.log as its log file. """ + blivet_log.setLevel(logging.DEBUG) + program_log = logging.getLogger("program") + program_log.setLevel(logging.DEBUG) + handler = logging.FileHandler("/tmp/blivet.log") + handler.setLevel(logging.DEBUG) + formatter = logging.Formatter("%(asctime)s,%(msecs)03d %(levelname)s %(name)s: %(message)s") + handler.setFormatter(formatter) + blivet_log.addHandler(handler) + program_log.addHandler(handler) + + +# doing this before importing blivet gets the logging from format class +# registrations and other stuff triggered by the import +set_up_logging() + +import blivet + +blivet_log.info(sys.argv[0]) + +storage = blivet.Blivet() # create an instance of Blivet +storage.reset() # detect system storage configuration + +for device in sorted(storage.devices, key=lambda d: len(d.ancestors)): + print device # this is a blivet.devices.StorageDevice instance + diff --git a/python-blivet.spec b/python-blivet.spec index fe905dd..cce0e8d 100644 --- a/python-blivet.spec +++ b/python-blivet.spec @@ -70,7 +70,7 @@ make DESTDIR=%{buildroot} install %files -f %{realname}.lang %defattr(-,root,root,-) -%doc README ChangeLog COPYING +%doc README ChangeLog COPYING examples %{python_sitelib}/* %changelog -- 1.8.1