~bladernr/checkbox/change-virt-test-ram

« back to all changes in this revision

Viewing changes to checkbox-support/checkbox_support/heuristics/udev.py

  • Committer: Sylvain Pineau
  • Date: 2014-01-07 13:39:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2588.
  • Revision ID: sylvain.pineau@canonical.com-20140107133938-46v5ehofwa9whl1e
checkbox-support: Copy required modules from checkbox-old/checkbox

and their corresponding tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of Checkbox.
 
2
#
 
3
# Copyright 2012 Canonical Ltd.
 
4
# Written by:
 
5
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
 
6
#
 
7
# Checkbox is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License version 3,
 
9
# as published by the Free Software Foundation.
 
10
 
 
11
#
 
12
# Checkbox is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
"""
 
21
checkbox.heuristics.dev
 
22
=======================
 
23
 
 
24
Heuristics for udev.
 
25
 
 
26
    Documentation: http://udisks.freedesktop.org/docs/latest/
 
27
    Source code: http://cgit.freedesktop.org/systemd/systemd/ (src/udev)
 
28
    Bug tracker: http://bugs.freedesktop.org/ (using systemd product)
 
29
"""
 
30
 
 
31
 
 
32
def is_virtual_device(device_file):
 
33
    """
 
34
    Given a device name like /dev/ramX, /dev/sdX or /dev/loopX determine if
 
35
    this is a virtual device. Virtual devices are typically uninteresting to
 
36
    users. The only exception may be nonempty loopback device.
 
37
 
 
38
    Possible prior art: gnome-disks, palimpset (precursor, suffering from this
 
39
    flaw and showing all the /dev/ram devices by default)
 
40
    """
 
41
    for part in device_file.split("/"):
 
42
        if part.startswith("ram") or part.startswith("loop"):
 
43
            return True
 
44
    return False