Beispiel #1
0
    def writedata(self):
        localtime = time.localtime()
        with codecs.open(datatempfilename, 'w', encoding='utf8') as f:
            f.write(u'''\
{date}
{time}
{S1Color.rH}
{S1rH}
{S2Color.rH}
{S2rH}
{S1Color.T}
{S1T}
{S2Color.T}
{S2T}
{S1Color.tau}
{S1tau}
{S2Color.tau}
{S2tau}
{fanstatestyle}
{modetxt}{fanstatetxt}
{statusstyle}
{statustxt}
{IPeth0}
{IPwlan0}
{IPwan}
{uptime}
{progtime}
{lastsync}'''.format(date=time.strftime("%d.%m.%Y", localtime),
                     time=time.strftime("%H:%M:%S", localtime),
                     S1rH=prettyPrint(self.S1.rH),
                     S2rH=prettyPrint(self.S2.rH),
                     S1T=prettyPrint(self.S1.T),
                     S2T=prettyPrint(self.S2.T),
                     S1tau=prettyPrint(self.S1.tau),
                     S2tau=prettyPrint(self.S2.tau),
                     S1Color=CSSstyle(self.S1),
                     S2Color=CSSstyle(self.S2),
                     statustxt=self.statustxt,
                     statusstyle=self.statusstyle,
                     modetxt=self.modetxt,
                     fanstatetxt=self.fanstatetxt,
                     fanstatestyle=self.fanstatestyle,
                     IPeth0=get_ip_address('eth0'),
                     IPwlan0=get_ip_address('wlan0'),
                     IPwan=get_wan_ip(),
                     uptime=str(datetime.timedelta(seconds=int(Uptime()))),
                     progtime=str(
                         datetime.timedelta(seconds=int(Uptime() -
                                                        progstart))),
                     lastsync=self.last_sync if self.last_sync else 'None'))
        os.rename(datatempfilename, datafilename)
Beispiel #2
0
 def display(self):
     infolines = (
         ['IP Ethernet/WLAN:'],
         ['', get_ip_address('eth0')],
         ['', get_ip_address('wlan0')],
         ['Bootvorgang vor:'],
         ['', str(datetime.timedelta(seconds=int(Uptime())))],
         ['Programmstart vor:'],
         ['', str(datetime.timedelta(seconds=int(Uptime() - self.progstart)))],
         ['Freies RAM:', getAvailableRAM()],
     )
     self.index = max(min(self.index, len(infolines) - self.displayLines), 0)
     self.messageboard.post(
         'Info',
         infolines[self.index:self.index + self.displayLines])
Beispiel #3
0
def mapEdit(request,layername):
   # res = None
   # if request.user.is_authenticated():
        #res = upload(request)
    # global tilestacheFile
    global TILECONFIG
    TILECONFIG = addLayer2tileConfig(request)
    global CFG
    CFG = TileStache.Config.buildConfiguration(TILECONFIG)
    mssStyle=open('media/mss2xml/save.mss').read()
    log = ""
    print request.method
    if request.method == "POST":
        mssStyle = request.POST['mssStyle']       
        log = mss2xml(mssStyle)
    if log==(0, 'SUCCESS'):
        file_object = open('media/mss2xml/save.mss', 'w')
        file_object.write(mssStyle)
        file_object.close( ) 
    #else:
       # mssStyle=open('media/mss2xml/save.mss','r').read()
    fonts = getFontList(request)
    port = '8888'
    ip_address = ip.get_ip_address('eth0')
    if(layername==request.user.username):
        port='8000'
        return render(request, 'pages/mapeditnew.html',{'ip':ip_address,'fonts':fonts,'layername':layername,'mssStyle':mssStyle,'log':log,'port':port,'isopen':'closed','display':'none'})
    return render(request, 'pages/basemap.html',{'ip':ip_address,'layername':layername,'port':port})
Beispiel #4
0
def run():
    while 1:
        with canvas(device) as draw:
            bt_is_connected(draw)
            addr = ip.get_ip_address('wlan0')
            wifi_is_connected(addr, draw)
            last_result(last_result_render(), draw)
            ip_address(addr, draw)
        time.sleep(20)
Beispiel #5
0
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
                             bridge, net_type, net_mtu, user_config,
                             is_ssh_address, is_container_address,
                             static_routes):
    """Process additional ip adds and append then to hosts as needed.

    If the host is found to be "is_metal" it will be marked as "on_metal"
    and will not have an additionally assigned IP address.

    :param key: ``str`` Component key name. This could be a group or a host
        name
    :param inventory: ``dict``  Living dictionary of inventory.
    :param ip_q: ``object`` build queue of IP addresses.
    :param q_name: ``str`` key to use in host vars for storage. May be blank.
    :param netmask: ``str`` netmask to use.
    :param interface: ``str`` interface name to set for the network.
    :param user_config: ``dict`` user defined configuration details.
    :param is_ssh_address: ``bol`` set this address as ansible_host.
    :param is_container_address: ``bol`` set this address to container_address.
    :param static_routes: ``list`` List containing static route dicts.
    """

    base_hosts = inventory['_meta']['hostvars']
    lookup = inventory.get(key, list())

    if 'children' in lookup and lookup['children']:
        for group in lookup['children']:
            _add_additional_networks(
                group,
                inventory,
                ip_q,
                q_name,
                netmask,
                interface,
                bridge,
                net_type,
                net_mtu,
                user_config,
                is_ssh_address,
                is_container_address,
                static_routes
            )

    # Make sure the lookup object has a value.
    if lookup:
        hosts = lookup.get('hosts')
        if not hosts:
            return
    else:
        return

    # TODO(cloudnull) after a few releases this should be removed.
    if q_name:
        old_address = '{}_address'.format(q_name)
    else:
        old_address = '{}_address'.format(interface)

    for container_host in hosts:
        container = base_hosts[container_host]

        # TODO(cloudnull) after a few releases this should be removed.
        # This removes the old container network value that now serves purpose.
        container.pop('container_network', None)

        if 'container_networks' in container:
            networks = container['container_networks']
        else:
            networks = container['container_networks'] = dict()

        is_metal = False
        properties = container.get('properties')
        if properties:
            is_metal = properties.get('is_metal', False)

        # This should convert found addresses based on q_name + "_address"
        #  and then build the network if its not found.
        if not is_metal and old_address not in networks:
            network = networks[old_address] = network_entry(
                is_metal,
                interface,
                bridge,
                net_type,
                net_mtu
            )
            if old_address in container and container[old_address]:
                network['address'] = container.pop(old_address)
            elif not is_metal:
                address = ip.get_ip_address(name=q_name, ip_q=ip_q)
                if address:
                    network['address'] = address

            network['netmask'] = netmask
        elif is_metal:
            network = networks[old_address] = network_entry(
                is_metal,
                interface,
                bridge,
                net_type,
                net_mtu
            )
            network['netmask'] = netmask
            if is_ssh_address or is_container_address:
                # Container physical host group
                cphg = container.get('physical_host_group')

                # user_config data from the container physical host group
                phg = user_config[cphg][container_host]
                network['address'] = phg['ip']

        if is_ssh_address is True:
            container['ansible_host'] = networks[old_address]['address']

        if is_container_address is True:
            container['container_address'] = networks[old_address]['address']

        if static_routes:
            # NOTE: networks[old_address]['static_routes'] will get
            #       regenerated on each run
            networks[old_address]['static_routes'] = []
            for route in static_routes:
                # only add static routes if they are specified correctly;
                # that is, the key and a value must be present. This doesn't
                # ensure that the values provided are routable, just that
                # they are not empty.
                cidr_present = route.get('cidr', False)
                gateway_present = route.get('gateway', False)

                if not (cidr_present and gateway_present):
                    raise MissingStaticRouteInfo(q_name)
                networks[old_address]['static_routes'].append(route)
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
                             bridge, net_type, net_mtu, user_config,
                             is_ssh_address, is_container_address,
                             static_routes):
    """Process additional ip adds and append then to hosts as needed.

    If the host is found to be "is_metal" it will be marked as "on_metal"
    and will not have an additionally assigned IP address.

    :param key: ``str`` Component key name. This could be a group or a host
        name
    :param inventory: ``dict``  Living dictionary of inventory.
    :param ip_q: ``object`` build queue of IP addresses.
    :param q_name: ``str`` key to use in host vars for storage. May be blank.
    :param netmask: ``str`` netmask to use.
    :param interface: ``str`` interface name to set for the network.
    :param user_config: ``dict`` user defined configuration details.
    :param is_ssh_address: ``bol`` set this address as ansible_host.
    :param is_container_address: ``bol`` set this address to container_address.
    :param static_routes: ``list`` List containing static route dicts.
    """

    base_hosts = inventory['_meta']['hostvars']
    lookup = inventory.get(key, list())

    if 'children' in lookup and lookup['children']:
        for group in lookup['children']:
            _add_additional_networks(group, inventory, ip_q, q_name, netmask,
                                     interface, bridge, net_type, net_mtu,
                                     user_config, is_ssh_address,
                                     is_container_address, static_routes)

    # Make sure the lookup object has a value.
    if lookup:
        hosts = lookup.get('hosts')
        if not hosts:
            return
    else:
        return

    # TODO(cloudnull) after a few releases this should be removed.
    if q_name:
        old_address = '{}_address'.format(q_name)
    else:
        old_address = '{}_address'.format(interface)

    for container_host in hosts:
        container = base_hosts[container_host]

        # TODO(cloudnull) after a few releases this should be removed.
        # This removes the old container network value that now serves purpose.
        container.pop('container_network', None)

        if 'container_networks' in container:
            networks = container['container_networks']
        else:
            networks = container['container_networks'] = dict()

        is_metal = False
        properties = container.get('properties')
        if properties:
            is_metal = properties.get('is_metal', False)

        # This should convert found addresses based on q_name + "_address"
        #  and then build the network if its not found.
        if not is_metal and old_address not in networks:
            network = networks[old_address] = network_entry(
                is_metal, interface, bridge, net_type, net_mtu)
            if old_address in container and container[old_address]:
                network['address'] = container.pop(old_address)
            elif not is_metal:
                address = ip.get_ip_address(name=q_name, ip_q=ip_q)
                if address:
                    network['address'] = address

            network['netmask'] = netmask
        elif is_metal:
            network = networks[old_address] = network_entry(
                is_metal, interface, bridge, net_type, net_mtu)
            network['netmask'] = netmask
            if is_ssh_address or is_container_address:
                # Container physical host group
                cphg = container.get('physical_host_group')

                # user_config data from the container physical host group
                phg = user_config[cphg][container_host]
                network['address'] = phg['ip']

        if is_ssh_address is True:
            container['ansible_host'] = networks[old_address]['address']

        if is_container_address is True:
            container['container_address'] = networks[old_address]['address']

        if static_routes:
            # NOTE: networks[old_address]['static_routes'] will get
            #       regenerated on each run
            networks[old_address]['static_routes'] = []
            for route in static_routes:
                # only add static routes if they are specified correctly;
                # that is, the key and a value must be present. This doesn't
                # ensure that the values provided are routable, just that
                # they are not empty.
                cidr_present = route.get('cidr', False)
                gateway_present = route.get('gateway', False)

                if not (cidr_present and gateway_present):
                    raise MissingStaticRouteInfo(q_name)
                networks[old_address]['static_routes'].append(route)
Beispiel #7
0
 def checkNetwork():
     return get_ip_address('wlan0') != 'None' or \
         get_ip_address('eth0') != 'None'
Beispiel #8
0
    def write(self):
        localtime = time.localtime()
        with codecs.open(pagetempfilename, 'w', encoding='utf8') as f:
            f.write(u'''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fan control</title>
<meta name="author" content="Daniel Müllner">
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {{ setTimeout("location.reload(true);",timeoutPeriod); }}
window.onload = timedRefresh(10000);
</script>
</head>
<style>
body {{font-family: sans-serif;}}
h1 {{font-size: 125%;}}
table {{border:1px solid grey;
border-collapse:collapse;}}
            td{{padding:4px 8px}}
tr.bg {{background-color:#ffb;}}
tr.hr {{border-bottom:1px solid black}}
td.l {{text-align:left;}}
td.c {{text-align:center;}}
td.r {{text-align:right;}}
</style>
<body>
<h1>Fan control</h1>
<table>
  <tr>
    <td colspan="3">
      {date}<span style="float:right">{time}</span>
    </td>
  </tr>
  <tr class="hr">
    <td>
    </td>
    <td class="c">
      Indoors
    </td>
    <td class="c">
      Outdoors
    </td>
  </tr>
  <tr class="bg">
    <td>
      Relative humidity in %
    </td>
    <td class="c" style="{S1Color.rH}">
      {S1rH}
    </td>
    <td class="c" style="{S2Color.rH}">
      {S2rH}
    </td>
  </tr>
  <tr>
    <td>
      Temperature in °C
    </td>
    <td class="c" style="{S1Color.T}">
      {S1T}
    </td>
    <td class="c" style="{S2Color.T}">
      {S2T}
    </td>
  </tr>
  <tr class="bg">
    <td>
      Dew point in °C
    </td>
    <td class="c" style="{S1Color.tau}">
      {S1tau}
    </td>
    <td class="c" style="{S2Color.tau}">
      {S2tau}
    </td>
  </tr>
  <tr>
    <td colspan="3" style="{fanstatestyle}">
      {modetxt}{fanstatetxt}
    </td>
  </tr>
  <tr class="bg hr">
    <td colspan="3" style="{statusstyle}">
      {statustxt}
    </td>
  </tr>
  <tr>
    <td colspan="3">
      IP Ethernet:&nbsp;<span style="float:right">{IPeth0}</span>
    </td>
  </tr>
  <tr class="bg">
    <td colspan="3">
      IP WLAN:&nbsp;<span style="float:right">{IPwlan0}</span>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      IP WAN:&nbsp;<span style="float:right">{IPwan}</span>
    </td>
  </tr>
  <tr class="bg">
    <td colspan="3">
      OS uptime:&nbsp;<span style="float:right">{uptime}</span>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      Controller uptime:&nbsp;<span style="float:right">{progtime}</span>
    </td>
  </tr>
  <tr class="bg">
    <td colspan="3">
      Last DCF77 signal:&nbsp;<span style="float:right">{lastsync}</span>
    </td>
  </tr>
</table>
</body>
</html>
'''.format(date=time.strftime("%d.%m.%Y", localtime),
            time=time.strftime("%H:%M:%S", localtime),
            S1rH=prettyPrint(self.S1.rH),
            S2rH=prettyPrint(self.S2.rH),
            S1T=prettyPrint(self.S1.T),
            S2T=prettyPrint(self.S2.T),
            S1tau=prettyPrint(self.S1.tau),
            S2tau=prettyPrint(self.S2.tau),
            S1Color=CSSstyle(self.S1),
            S2Color=CSSstyle(self.S2),
            statustxt=self.statustxt,
            statusstyle=self.statusstyle,
            modetxt=self.modetxt,
            fanstatetxt=self.fanstatetxt,
            fanstatestyle=self.fanstatestyle,
            IPeth0=get_ip_address('eth0'),
            IPwlan0=get_ip_address('wlan0'),
            IPwan=get_wan_ip(),
            uptime=str(datetime.timedelta(seconds=int(Uptime()))),
            progtime=str(datetime.timedelta(seconds=int(Uptime() - progstart))),
            lastsync=self.last_sync if self.last_sync else 'None'))
        os.rename(pagetempfilename, pagefilename)