示例#1
0
def update(pm):

    """"""

    if pm == "aptitude":
        command_line = "aptitude search ~U"
    elif pm == "dnf":
        command_line = "dnf check-update"
    elif pm == "pacman":
        command_line = "checkupdates"
        command_line_a = "cower --color=never -uq"
    else:
        print("Error: unknown package manager")

    update = methods.call_command(command_line).split('\n')
    repo = len(update) - 1

    if check.prg("cower"):
        update_aur = []
        for line in methods.call_command(command_line_a).split():
            if line.startswith("error"):
                pass
            else:
                update_aur.append(line)
        aur = len(update_aur)

    return(str(repo), str(aur))
示例#2
0
    def space_info(size="gb"):

        """(list) return a list containing total space, free space, used space and
        service name. Have one optional arguments: the measure unit you want to use to
        the output data (default = Gb)"""

        out = []
        _size = "--" + size

        s = methods.call_command("megadf " + _size)

        for line in s.split(sep='\n'):
            line = re.sub(r'\s', '\n', line)
            for line in line.split(sep='\n'):
                if line.isdigit():
                    line = line + '.0'
                    out.append(line)

        out.append("mega")

        pfree = 100 * float(out[2]) // float(out[0])
        pused = 100 * float(out[1]) // float(out[0])

        out.append(str(pfree))
        out.append(str(pused))

        return(out)
示例#3
0
def cpu():
    command_line = "cat /proc/cpuinfo"

    collect_info = [line.split(":") for line in methods.call_command(command_line).split("\n") if line]
    infodict = {}
    for k, v in collect_info:
        infodict[k.strip()] = v.strip()

    return(infodict["model name"])
示例#4
0
def ram():
    command_line = "free -m"

    values = ''.join(line for line in methods.call_command(command_line).split('\n') if line.startswith('Mem:')).split()

    used_perc = int(values[2]) * 100 // int(values[1])
    free_perc = 100 - used_perc

    values.append(str(used_perc))
    values.append(str(free_perc))

    return(values)
示例#5
0
def fs(mountpoint):
    command_line = "df -TPh " + os.path.expanduser(mountpoint)

    values = [line for line in methods.call_command(command_line).split('\n') if line][1].split()

    free_perc = 100 - int(values[5][:-1])
    free_perc = str(free_perc) + '%'
    values.append(free_perc)

    name = values[6]
    if name == "/":
        name = "Root"
    else:
        name = name.split('/')[1].strip('/').title()
    values.append(name)

    return(values)
示例#6
0
    def space_info(remote, service):

        """(list) return a list containing total space, free space, used space
        and service name (e.g. dropbox, drive etc). Require two arguments: the name of
        the remote set with rclone and the name of the cloud service"""

        cloud_storage = remote + ":"

        size = methods.call_command("rclone size " + cloud_storage)

        for line in size.split(sep='\n'):
            if line.startswith("Total size"):
                tot = line

        tot = re.sub(r'\s', '\n', tot)

        l = []
        for item in tot.split(sep='\n'):
            l.append(item)

        used_space = l[2][:-1]

        if service == "dropbox":
            total_space = float(20)
        elif service == "drive":
            total_space = float(15)
        else:
            print("Service not found")
            sys.exit(1)

        free_space = total_space - float(used_space)

        used_space = "{0:.1f}".format(float(used_space))
        free_space = "{0:.1f}".format(free_space)

        pfree = 100 * float(free_space) // int(total_space)
        pused = 100 * float(used_space) // int(total_space)

        out = [str(total_space), str(free_space), used_space, service, str(pfree), str(pused)]

        return(out)
示例#7
0
def wifi_info(interface):
    command_line = "iwconfig %s" %interface

    info = methods.call_command(command_line)

    info_ = [info.split()[0]]

    for item in info.split():
        if item.startswith("ESSID"):
            item = item.split(':')
            info_.append(item[1].strip('"'))
        elif item.startswith('Quality'):
            item = item.split('=')
            item = item[1].split('/')
            q = item[0]
            p = int(q) * 100 // 70
            info_.append(str(p))
        else:
            pass    

    return(info_)
示例#8
0
def process_exists(proc):
    command_line = "ps -u " + os.environ["USER"]
    for line in methods.call_command(command_line).split():
        if line == proc:
            return True