Beispiel #1
0
    def __init__(self):
        self.vendor = pdos.readFile(
            '/sys/devices/virtual/dmi/id/sys_vendor')[0]
        self.board = pdos.readFile('/sys/devices/virtual/dmi/id/product_name')[0] \
                     + ' ' + pdos.readFile('/sys/devices/virtual/dmi/id/product_version')[0]
        self.cpu = platform.processor()
        self.memory = virtual_memory().total

        self.wifi = []
        devices = detectSystemDevices()
        for wifiDev in devices['wifi']:
            self.wifi.append({
                'id': wifiDev['id'],
                'macAddr': wifiDev['mac'],
                'vendorId': wifiDev['vendor'],
                'deviceId': wifiDev['device'],
                'slot': wifiDev['slot']
            })

        self.biosVendor = pdos.readFile(
            '/sys/devices/virtual/dmi/id/bios_vendor')[0]
        self.biosVersion = pdos.readFile(
            '/sys/devices/virtual/dmi/id/bios_version')[0]
        self.biosDate = pdos.readFile(
            '/sys/devices/virtual/dmi/id/bios_date')[0]
        self.osVersion = getOSVersion()
        self.kernelVersion = platform.system() + '-' + platform.release()
        self.pdVersion = getPackageVersion('paradrop')
        self.uptime = int(float(pdos.readFile('/proc/uptime')[0].split()[0]))
Beispiel #2
0
def isWAN(ifname):
    """
    Test if an interface is a WAN interface.
    """
    pattern = re.compile(r"(\w+)\s+(\w+)*")
    routeList = pdos.readFile("/proc/net/route")
    for line in routeList:
        match = pattern.match(line)
        if match is not None and \
                match.group(1) == ifname and \
                match.group(2) == "00000000":
            return True
    return False
Beispiel #3
0
def isWAN(ifname):
    """
    Test if an interface is a WAN interface.
    """
    pattern = re.compile(r"(\w+)\s+(\w+)*")
    routeList = pdos.readFile("/proc/net/route")
    for line in routeList:
        match = pattern.match(line)
        if match is not None and \
                match.group(1) == ifname and \
                match.group(2) == "00000000":
            return True
    return False
Beispiel #4
0
    def __init__(self):
        self.password_file = os.path.join(settings.CONFIG_HOME_DIR, 'password')

        # Try to parse the password file
        # self.records will have the pairs of user name and password hash
        parsed = False
        if pdos.exists(self.password_file):
            lines = pdos.readFile(self.password_file)
            if lines:
                for line in lines:
                    elements = line.split(':')
                    if len(elements) == 2:
                        self.records = []
                        self.records.append({
                            'user_name': elements[0],
                            'password_hash': elements[1]
                        })
                if len(lines) == len(self.records):
                    parsed = True
                else:
                    self.records = []

        if not parsed:
            self.reset()
    def __init__(self):
        self.password_file = os.path.join(settings.CONFIG_HOME_DIR, 'password')

        # Try to parse the password file
        # self.records will have the pairs of user name and password hash
        parsed = False
        if pdos.exists(self.password_file):
            lines = pdos.readFile(self.password_file)
            if lines:
                for line in lines:
                    elements = line.split(':')
                    if len(elements) == 2:
                        self.records = []
                        self.records.append({
                            'user_name': elements[0],
                            'password_hash': elements[1]
                        })
                if len(lines) == len(self.records):
                    parsed = True
                else:
                    self.records = []

        if not parsed:
            self.reset()
Beispiel #6
0
def test_pdos():
    """
    Test pdos utility module
    """
    assert pdos.getMountCmd() == "mount"
    assert pdos.isMount("/")
    assert pdos.ismount("/")

    assert pdos.oscall("true") is None
    assert pdos.oscall("false") is not None
    assert pdos.oscall("echo hello") is None
    assert pdos.oscall("echo hello 1>&2") is None

    assert pdos.syncFS() is None

    # Make a file, check that our functions respond correctly to it
    path = writeTempFile("hello")
    assert pdos.fixpath(path) == path
    assert "text" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert not pdos.isdir(path)
    assert pdos.isfile(path)

    # Remove the file, check that our functions detect that
    pdos.unlink(path)
    assert pdos.fixpath(path) == path
    assert pdos.getFileType(path) is None
    assert not pdos.exists(path)
    assert not pdos.isdir(path)
    assert not pdos.isfile(path)

    # Make a directory there instead
    pdos.mkdir(path)
    assert pdos.fixpath(path) == path
    assert "directory" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert pdos.isdir(path)
    assert not pdos.isfile(path)

    # Now we will do some manipulations on files under that directory
    a = os.path.join(path, "a")
    b = os.path.join(path, "b")
    c = os.path.join(path, "c")
    d = os.path.join(path, "d")

    pdos.write(a, "hello")
    assert pdos.isfile(a)
    pdos.copy(a, b)
    assert pdos.isfile(b)
    pdos.symlink(a, c)
    assert pdos.isfile(c)
    pdos.move(a, b)
    assert not pdos.isfile(a)
    pdos.remove(b)
    assert not pdos.isfile(b)
    pdos.mkdir(a)
    pdos.copytree(a, b)
    assert pdos.isdir(b)

    # Remove a non-empty directory
    pdos.remove(path)
    assert not pdos.isdir(path)

    # This file is under a directory that no longer exists, so the write must
    # fail.
    #
    # TODO: These should not fail silently.  They should either return an error
    # indicator or raise an exception.
    pdos.writeFile(a, "c")
    pdos.write(a, "c")

    # Test various ways to call writeFile
    pdos.writeFile(path, ["a", "b"])
    pdos.writeFile(path, "c")
    pdos.writeFile(path, 5)  # This one does nothing.

    # Test the content with readFile
    data = pdos.readFile(path, array=False, delimiter="")
    assert data == "abc"
    data = pdos.readFile(path, array=True)
    assert data == ["a", "b", "c"]
    pdos.remove(path)
    assert pdos.readFile(path) is None
Beispiel #7
0
def test_pdos():
    """
    Test pdos utility module
    """
    assert pdos.getMountCmd() == "mount"
    assert pdos.isMount("/")
    assert pdos.ismount("/")

    assert pdos.oscall("true") is None
    assert pdos.oscall("false") is not None
    assert pdos.oscall("echo hello") is None
    assert pdos.oscall("echo hello 1>&2") is None

    # Make a file, check that our functions respond correctly to it
    path = writeTempFile("hello")
    assert pdos.fixpath(path) == path
    assert "text" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert not pdos.isdir(path)
    assert pdos.isfile(path)

    # Remove the file, check that our functions detect that
    pdos.unlink(path)
    assert pdos.fixpath(path) == path
    assert pdos.getFileType(path) is None
    assert not pdos.exists(path)
    assert not pdos.isdir(path)
    assert not pdos.isfile(path)

    # Make a directory there instead
    pdos.mkdir(path)
    assert pdos.fixpath(path) == path
    assert "directory" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert pdos.isdir(path)
    assert not pdos.isfile(path)

    # Now we will do some manipulations on files under that directory
    a = os.path.join(path, "a")
    b = os.path.join(path, "b")
    c = os.path.join(path, "c")
    d = os.path.join(path, "d")

    pdos.write(a, "hello")
    assert pdos.isfile(a)
    pdos.copy(a, b)
    assert pdos.isfile(b)
    pdos.symlink(a, c)
    assert pdos.isfile(c)
    pdos.move(a, b)
    assert not pdos.isfile(a)
    pdos.remove(b)
    assert not pdos.isfile(b)
    pdos.mkdir(a)
    pdos.copytree(a, b)
    assert pdos.isdir(b)

    # Remove a non-empty directory
    pdos.remove(path)
    assert not pdos.isdir(path)

    # This file is under a directory that no longer exists, so the write must
    # fail.
    #
    # TODO: These should not fail silently.  They should either return an error
    # indicator or raise an exception.
    pdos.writeFile(a, "c")
    pdos.write(a, "c")

    # Test various ways to call writeFile
    pdos.writeFile(path, ["a", "b"])
    pdos.writeFile(path, "c")
    pdos.writeFile(path, 5)  # This one does nothing.

    # Test the content with readFile
    data = pdos.readFile(path, array=False, delimiter="")
    assert data == "abc"
    data = pdos.readFile(path, array=True)
    assert data == ["a", "b", "c"]
    pdos.remove(path)
    assert pdos.readFile(path) is None