/[smeserver]/cdrom.image/sme9/updates/storage/miscutils.py
ViewVC logotype

Contents of /cdrom.image/sme9/updates/storage/miscutils.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Dec 22 04:27:51 2013 UTC (10 years, 7 months ago) by wellsi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-python
FILE REMOVED
anaconda updates now handled via patches

1 # iutil.py stubs
2 import os
3
4 import logging
5 log = logging.getLogger("storage")
6
7 def notify_kernel(path, action="change"):
8 """ Signal the kernel that the specified device has changed. """
9 log.debug("notifying kernel of '%s' event on device %s" % (action, path))
10 path = os.path.join(path, "uevent")
11 if not path.startswith("/sys/") or not os.access(path, os.W_OK):
12 log.debug("sysfs path '%s' invalid" % path)
13 raise ValueError("invalid sysfs path")
14
15 f = open(path, "a")
16 f.write("%s\n" % action)
17 f.close()
18
19 def get_sysfs_path_by_name(dev_name, class_name="block"):
20 dev_name = os.path.basename(dev_name)
21 sysfs_class_dir = "/sys/class/%s" % class_name
22 dev_path = os.path.join(sysfs_class_dir, dev_name)
23 if os.path.exists(dev_path):
24 return dev_path
25
26 import inspect
27 def log_method_call(d, *args, **kwargs):
28 classname = d.__class__.__name__
29 methodname = inspect.stack()[1][3]
30 fmt = "%s.%s:"
31 fmt_args = [classname, methodname]
32 for arg in args:
33 fmt += " %s ;"
34 fmt_args.append(arg)
35
36 for k, v in kwargs.items():
37 fmt += " %s: %s ;"
38 fmt_args.extend([k, v])
39
40 log.debug(fmt % tuple(fmt_args))
41
42 def numeric_type(num):
43 """ Verify that a value is given as a numeric data type.
44
45 Return the number if the type is sensible or raise ValueError
46 if not.
47 """
48 if num is None:
49 num = 0
50 elif not (isinstance(num, int) or \
51 isinstance(num, long) or \
52 isinstance(num, float)):
53 raise ValueError("value (%s) must be either a number or None" % num)
54
55 return num
56
57

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed