Esempio n. 1
0
file's mtime. The metadata may also have the "directory" value.

get_filename(metadata, [directory]) : return a file name encoding the given
metadata values.

"""

import sys
import os
import re

from pycopia import aid
from pycopia import dictlib
from pycopia import timelib

OFF = aid.Enum(0, "OFF")
ON = aid.Enum(1, "ON")
UNKNOWN = aid.Enum(-1, "UNKNOWN")

_STATE_RE = re.compile(r"(\w+)(ON|OFF|UNKNOWN)")
_STATEMAP = {
    "ON": ON,
    "OFF": OFF,
    "UNKNOWN": UNKNOWN,
}

_OTHERDATA_RE = re.compile(r"([a-z]+)([A-Z0-9.,\-]+)")


def get_filename(metadata, directory=None, ext="txt"):
    """Construct data file name from a metadata dictionary.
Esempio n. 2
0
# map libsmi constant values to RFC 2578 (and other) defined names for the
# enumeration's name. If not listed here then use the flag name itself.
_NAMES = {
    "SMI_BASETYPE_BITS": "Bits",
    "SMI_BASETYPE_ENUM": "Enumeration",
    "SMI_BASETYPE_FLOAT128": "Float128",
    "SMI_BASETYPE_FLOAT32": "Float32",
    "SMI_BASETYPE_FLOAT64": "Float64",
    "SMI_BASETYPE_INTEGER32": "Integer32",
    "SMI_BASETYPE_INTEGER64": "Integer64",
    "SMI_BASETYPE_OBJECTIDENTIFIER": "ObjectIdentifier",
    "SMI_BASETYPE_OCTETSTRING": "OctetString",
    "SMI_BASETYPE_UNSIGNED32": "Unsigned32",
    "SMI_BASETYPE_UNSIGNED64": "Counter64",
    "SMI_ACCESS_NOT_ACCESSIBLE": "not-accessible",
    "SMI_ACCESS_NOTIFY": "accessible-for-notify",
    "SMI_ACCESS_READ_ONLY": "read-only",
    "SMI_ACCESS_READ_WRITE": "read-write",
    "SMI_STATUS_CURRENT": "current",
    "SMI_STATUS_DEPRECATED": "deprecated",
    "SMI_STATUS_OBSOLETE": "obsolete",
}

# pull C #defines from _libsmi C module, assign to Enum types. Override the
# default name with one from the _NAMES mapping, if it exists.
for name, value in vars(_libsmi).items():
    if name.startswith("SMI_") and type(value) is int:
        setattr(sys.modules[__name__], name,
                aid.Enum(value, _NAMES.get(name, name)))
del name, value, _libsmi, sys, _NAMES
Esempio n. 3
0
def _enum_decoder(d):
    return aid.Enum(int(d["value"]), d["_str_"])
Esempio n. 4
0
from pycopia import aid

from droid.instruments import core


class Error(Exception):
  pass

class CommandError(Error):
  pass

class ExecutionError(Error):
  pass

# call states
SETUP = aid.Enum(0, "SETUP")
ONHOOK = aid.Enum(1, "ONHOOK")
ALERTING = aid.Enum(2, "ALERTING")
PROCEED = aid.Enum(2, "PROCEED")
RINGING = aid.Enum(4, "RINGING")
CONNECTED = aid.Enum(6, "CONNECTED")


class CallerID(object):
  def __init__(self, number, type, valid):
    self.number = number
    self.type = type
    self.valid = valid

  def __str__(self):
    if self.valid == 0:
Esempio n. 5
0
 def _set_error(self, err):
     if err is not None:
         self._error = aid.Enum(err[0], err[1])
Esempio n. 6
0
# Copyright The Android Open Source Project
"""Common components of instrument package.

"""

import sys

import numpy
from pycopia import aid

from droid.util import module
from droid.physics import physical_quantities

PQ = physical_quantities.PhysicalQuantity

ON = aid.Enum(1, "ON")
OFF = aid.Enum(0, "OFF")

_config = None
_instrumentcache = {}


class NoSuchDevice(Exception):
    pass


class DeviceError(object):
    """Represents an error code from device.
  """
    def __init__(self, code, string):
        self._code = code
Esempio n. 7
0
# enumeration's name. If not listed here then use the flag name itself.
_NAMES = {
    "SMI_BASETYPE_BITS":               "Bits",
    "SMI_BASETYPE_ENUM":               "Enumeration",
    "SMI_BASETYPE_FLOAT128":           "Float128",
    "SMI_BASETYPE_FLOAT32":            "Float32",
    "SMI_BASETYPE_FLOAT64":            "Float64",
    "SMI_BASETYPE_INTEGER32":          "Integer32",
    "SMI_BASETYPE_INTEGER64":          "Integer64",
    "SMI_BASETYPE_OBJECTIDENTIFIER":   "ObjectIdentifier",
    "SMI_BASETYPE_OCTETSTRING":        "OctetString",
    "SMI_BASETYPE_UNSIGNED32":         "Unsigned32",
    "SMI_BASETYPE_UNSIGNED64":         "Counter64",
    "SMI_ACCESS_NOT_ACCESSIBLE":       "not-accessible",
    "SMI_ACCESS_NOTIFY":               "accessible-for-notify",
    "SMI_ACCESS_READ_ONLY":            "read-only",
    "SMI_ACCESS_READ_WRITE":           "read-write",
    "SMI_STATUS_CURRENT":              "current",
    "SMI_STATUS_DEPRECATED":           "deprecated",
    "SMI_STATUS_OBSOLETE":             "obsolete",
}

# pull C #defines from _libsmi C module, assign to Enum types. Override the
# default name with one from the _NAMES mapping, if it exists.
for name, value in vars(_libsmi).items():
    if name.startswith("SMI_") and type(value) is int:
        setattr(sys.modules[__name__], name, aid.Enum(value, _NAMES.get(name, name)))
del name, value, _libsmi, sys, _NAMES