Пример #1
0
def solve(datafile="input.txt"):
    ss = []
    with open(resolve(datafile)) as f:
        while True:
            try:
                ss.append(Scanner.read(f))
            except IOError:
                break

    g = defaultdict(set)
    for i in range(len(ss)):
        for j in range(i + 1, len(ss)):
            if ss[i].overlap(ss[j]):
                g[i].add(j)
                g[j].add(i)

    os = {0}
    ss[0].aligned = True
    while os:
        n = os.pop()
        for i in g[n]:
            if not ss[i].aligned:
                ss[i] = ss[n].align(ss[i])
                os.add(i)

    assert all(_.aligned for _ in ss)

    return (
        len({_
             for s in ss for _ in s}),
        int(max(ss[i].m(ss[j]) for i in range(len(ss))
                for j in range(len(ss)))),
    )
Пример #2
0
def getDiskSpace():
    p = pop("df -h /")
    i = 0
    while 1:
        i = i + 1
        line = p.readline()
        if i == 2:
            return (line.split()[1:5])
Пример #3
0
def getRAMinfo():
    p = pop('free')
    i = 0
    while 1:
        i = i + 1
        line = p.readline()
        if i == 2:
            return (line.split()[1:4])
Пример #4
0
    def overlays_list_sorted(self):
        '''
        Resolve inter-overlay dependencies, and place a sorted list
        of overlays, where there would be no dependency issues upon
        starting them, in place of the existing list.
        '''

        os = sorted(self.overlays.keys())
        sos = []

        while os:
            self._overlays_list_sorted(os, sos, self.overlays[os.pop(0)])

        return sos
Пример #5
0
    def value_for_field(self, obj, field):
        if not field.startswith("structures") and not field.startswith(
                "tables"):
            raise UnknownFieldError

        field_split = field.split(".")
        field_len = len(field_split)
        if field_len > 2:
            raise UnknownFieldError

        # add structures and tables info to response if requested
        from mpcontribs.api.structures.views import StructuresResource
        from mpcontribs.api.tables.views import TablesResource

        mask = ["id", "label", "name"]
        # return full structures/tables only if download requested
        full = bool(self.view_method == Download
                    and self.params.get("_fields") == "_all")
        fmt = self.params.get("format")
        kwargs = dict(contribution=obj.id)
        if field_len == 2:
            # requested structure/table(s) for specific label
            kwargs["label"] = field_split[1]

        if field.startswith("structures"):
            res = StructuresResource(view_method=self.view_method)
            if full and fmt == "json":
                mask += ["lattice", "sites", "charge", "klass", "module"]
            objects = Structures.objects.only(*mask)
        else:
            res = TablesResource(view_method=self.view_method)
            # TODO adjust mask for full json format
            objects = Tables.objects.only(*mask)

        objects = objects.filter(**kwargs).order_by("-id")
        result = defaultdict(list)
        for o in objects:
            os = res.serialize(o, fields=mask)
            # TODO res.value_for_field(o, "cif") if fmt == "csv" and field.startswith("structures")
            result[os.pop("label")].append(os)

        ret = result if field_len == 1 else list(result.values())[0]
        obj.update(**{f"set__{field.replace('.', '__')}": ret})
        return ret
Пример #6
0
def cacher_to_metadata(j, tinkerbell):
    instance = j.get("instance", None)
    if not instance:
        os = j["preinstalled_operating_system_version"]
        storage = os.pop("storage")
        instance = {
            "crypted_root_password": "******",
            "hostname": "preinstall",
            "id": "preinstall",
            "ip_addresses": [],
            "operating_system_version": os,
            "storage": storage,
            "userdata": None,
        }

    os = instance["operating_system_version"]
    os["slug"] = os["os_slug"]
    return {
        "class": j["plan_slug"],
        "facility": j["facility_code"],
        "hostname": instance["hostname"],
        "id": instance["id"],
        "network": {
            "addresses":
            instance.get("ip_addresses", []),
            "bonding": {
                "mode": j["bonding_mode"]
            },
            "interfaces": [{
                "bond": p["data"]["bond"],
                "mac": p["data"]["mac"],
                "name": p["name"]
            } for p in j["network_ports"] if p["type"] == "data"],
        },
        "operating_system": os,
        "password_hash": instance.get("crypted_root_password"),
        "phone_home_url": parse.urljoin(tinkerbell.geturl(), "phone-home"),
        "plan": j["plan_slug"],
        "services": instance.get("services"),
        "state": j["state"],
        "storage": instance.get("storage", ""),
    }  # noqa: E122
Пример #7
0
        def _wordify (stream):

            stream = stream.execute(self.env)
            stream = stream.subst()

            # Ensure the stream is a sequence of complete words (ie,
            # concatenate successive text parts and space parts).  The
            # comma must remain on its own, as it serves as a separator.
            # The dot is always appended to the previous word.

            in_space = True
            os, stream = stream, []

            while os:
                s = os.pop (0)
                
                if s == '.':
                    stream [-1] += '.'
                    in_space = True
                    continue

                is_space = s in (' ', '\n')

                if in_space:
                    if not is_space:
                        stream.append (s)
                        in_space = False
                    continue

                else:
                    if is_space:
                        in_space = True
                    else:
                        if s == ',':
                            stream.append (s)
                            in_space = True
                        else:
                            stream [-1] += s
                    
            return stream
Пример #8
0
#!/usr/bin/python

from os import system as ss
from time import sleep as sl
from os import popen as pop
import os

while True:

    passs1 = list(pop('smartctl -H /dev/sda1').read())
    os.system('smartctl -H /dev/sda1')
    sl(1)
    passs2 = list(pop('smartctl -H /dev/sda2').read())
    os.system('smartctl -H /dev/sda2')
    sl(1)
    passs3 = list(pop('smartctl -H /dev/sda5').read())
    os.system('smartctl -H /dev/sda5')
    sl(1)
    passs4 = list(pop('smartctl -H /dev/sda6').read())
    os.system('smartctl -H /dev/sda6')
    sl(1)

    oke1 = []
    oke2 = []
    oke3 = []
    oke4 = []

    oke1.append(passs1[-8])
    oke1.append(passs1[-7])
    oke1.append(passs1[-6])
    oke1.append(passs1[-5])
Пример #9
0
def getCPUuse():
    return(str(pop("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip(\
)))
Пример #10
0
def getCPUtemperature():
    res = pop('vcgencmd measure_temp').readline()
    return (res.replace("temp=", "").replace("'C\n", ""))