コード例 #1
0
    def water_for_x(sec):
        from os import system as system_call
        import time
        time.sleep(5)

        # todo Email an mich, dass es los geht mit sleep(300)

        for x in range(5):
            has_problem = system_call(
                "gatttool -b BB:A0:56:02:28:11 --char-write --handle 0x000f --value C5043132333435363738AA"
            )
            if not has_problem:
                print("Successfully STARTED watering for {} seconds!".format(
                    sec))
                break
            print("ERROR on try #{} to START watering for {} seconds!".format(
                x, sec))

        time.sleep(sec)

        for x in range(20):
            has_problem = system_call(
                "gatttool -b BB:A0:56:02:28:11 --char-write --handle 0x000f --value C5063132333435363738AA"
            )
            if not has_problem:
                print("Successfully STOPPED watering for {} seconds!".format(
                    sec))
                break
            print("ERROR on try #{} to STOP watering for {} seconds!".format(
                x, sec))
コード例 #2
0
	def clear(self):
		"""
		Helpful code to clear the screen from StackOverflow
		https://stackoverflow.com/questions/18937058/clear-screen-in-shell/31871439
		"""
		command = "cls" if system_name().lower()=="windows" else "clear"
		system_call(command)
コード例 #3
0
 def clear_shell_screen():
     """
     clears the shell screen
     :return: None
     :rtype: None
     """
     cmd = "cls" if system_name().lower() == "windows" else "clear"
     system_call(cmd)
コード例 #4
0
def clear_screen():
    """
    Clears the terminal screen.
    """
    # Clear command as function of OS
    command = "cls" if system_name().lower() == "windows" else "clear"
    # Action
    system_call(command)
コード例 #5
0
def clear_screen():
    """Clears the terminal screen."""
    if system_name().lower() == "windows":
        command = "cls"
    else:
        command = "clear"

    system_call(command)
コード例 #6
0
ファイル: libEnv.py プロジェクト: manoj14-ML/MyPOC
def clear_screen_old():

    # Clear command as function of OS
    command = "cls" if system_name().lower()=="windows" else "clear"

    # Action
    system_call(command)
	
	
コード例 #7
0
def ctrl_caught(signal, frame):
    print("\nSIGINT caught, quitting")
    system_call(
        'if [ -n "$TMUX" ]; then tmux rename-window -t${TMUX_PANE} $(hostname);fi'
    )
    try:
        curses.endwin()
    except curses.error:
        pass
    exit(1)
コード例 #8
0
def ping_ip(ip, timeout):
    """
    Ping an IP address
    https://stackoverflow.com/questions/2953462/pinging-servers-in-python
    
    Args:
        ip (str): ip address
        timeout (int, optional): length of time for the function to return
        timeout status. 
    
    Returns:
        str: OFFLINE if the device is OFFLINE
             ONLINE if the device is ONLINE 
    """
    if system_name().lower() == "windows":
        #  -w is timeout -n is number of packets
        params = "-w {} -n 1".format(
            timeout * 1000
        )  # convert seconds to mills for non-windows

    else:
        #  -W is timeout -c is number of packets
        params = "-W {} -c 1".format(timeout)

    response = system_call("ping " + params + " " + ip)

    # logger.debug(str(response))

    if response != 0:
        return "OFFLINE"
    else:
        return "ONLINE"
コード例 #9
0
def ping(host, quant):
    if (system_name().upper() == "WINDOWS"):
        parametros = ("-n %s" % quant)
    else:
        parametros = ("-c %s" % quant)

    return system_call("ping " + parametros + " " + host) == 0
コード例 #10
0
def ping(host):
    # Ping parameters as function of OS
    # Works with Windows, OS X, or Linux
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"

    # Pinging
    return system_call("ping " + parameters + " " + host) == 0
コード例 #11
0
def ping_host(host, count=1):
    """Check a hosts availability
    :param host:
    :param count:
    :rtype: boolean
    """
    print(".: {} ping {} x {}".format(txt.INF_CLR, host, count))
    return system_call("ping -c{} {} > /dev/null".format(count, host)) == 0
コード例 #12
0
def check_ping(host):
    """
    Returns True if host (str) responds to a ping request.
    Remember that some hosts may not respond to a ping request even if the host name is valid.
    """
    # Ping parameters as function of OS
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"
    # Pinging
    return system_call("ping " + parameters + " " + host) == 0
コード例 #13
0
def upload_folder(collect_folder, target_folder):
    print('start_uploading')
    command = 'aws s3 sync ./{} {}{}/{}/{}/{}/{}/{}/{} --profile {}'.format(
        collect_folder, S3_BASE, BUCKET, KIND, CITY, TAG, VENDER, BOARD,
        target_folder, USER)
    try:
        return system_call(command) == 0
    except Exception as e:
        return False
コード例 #14
0
def ping_host(host: str, tty: bool = False, count: int = 1) -> bool:
    """Check a hosts availability
    :param host:
    :param count:
    :param tty:
    :rtype: boolean
    """
    util.msg(f"ping {host} x {count}", urgency=txt.INF_CLR, tty=tty)
    return system_call("ping -c{} {} > /dev/null".format(count, host)) == 0
コード例 #15
0
def ping(ip):
    if system_name().lower()=="windows":    # Checks for system name
        parameters = "-n 1"                 # If windows-> -n 1
    else:
        parameters = "-c 1"                 # If not windows -> -c 1
    if system_call("ping "+parameters+" "+ip) == 0: # Pings client
        status = "Online"
    else:
        status = "Offline"
    return status
コード例 #16
0
def spawn(name, wlan, ssid, password):
    c = from_env().containers.get(name)
    iwcall = 'iw phy phy{0} set netns {1}'.format(wlan[-1],
                                                  c.attrs['State']['Pid'])
    wpacall = 'sh -c "wpa_passphrase {0} {1} > /tmp/wpa.conf"'.format(
        ssid, password)
    supcall = 'sudo wpa_supplicant -B -i {0} -c /tmp/wpa.conf'.format(wlan)
    print(system_call(iwcall))
    print(c.exec_run(wpacall))
    print(c.exec_run(supcall))
    print(c.exec_run('sudo dhcpcd {0}'.format(wlan)))
コード例 #17
0
def ping(host, count=4):
    """
    Returns True if host (str) responds to a ping request.
    Remember that some hosts may not respond to a ping request even if the host name is valid.
    """
    parameters = "-n " + str(count) if system_name().lower() == "windows" else "-c " + str(count)
    status = system_call("ping " + parameters + " " + host)
    if status == 0:
        return True
    else:
        return False
コード例 #18
0
ファイル: utils.py プロジェクト: antonbil/pymopid
def ping(host):
    """
    Returns True if host (str) responds to a ping request.
    Remember that some hosts may not respond to a ping request even if the host name is valid.
    """

    # Ping parameters as function of OS
    ping_param = "-c 3"

    # Pinging ["ping", "-c", "3", hostname]
    return system_call("ping " + ping_param + " " + host) == 0
コード例 #19
0
def spawn(name, wlan, ssid, password):
    c = from_env().containers.get(name)
    iwcall = 'PHY="phy"`iw dev {0} info | grep wi | grep -Eo ".{{1}}$"`; iw phy $PHY set netns {1}'.format(
        wlan, c.attrs['State']['Pid'])
    wpacall = 'sh -c "wpa_passphrase {0} {1} > /tmp/wpa.conf"'.format(
        ssid, password)
    supcall = 'sudo wpa_supplicant -B -i {0} -c /tmp/wpa.conf'.format(wlan)
    print(system_call(iwcall))
    print(c.exec_run(wpacall))
    print(c.exec_run(supcall))
    print(c.exec_run('sudo dhcpcd {0}'.format(wlan)))
コード例 #20
0
ファイル: network.py プロジェクト: vligade/aws-12
 def _ping(self, server):
     print "[*] Start to ping server %s" % server
     # Ping parameters as function of OS
     parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"
     # Pinging
     time.sleep(1)
     try:
         if system_call("ping " + parameters + " " + server) == 0:
             print "[*] Ping is reachable to server %s" % server
             return True
     except:
         pass
コード例 #21
0
 def get(self):
     ping_param = "-n 1" if system().lower()=="windows" else "-c 1"
     hasInternet = system_call("ping " + ping_param + " github.com") == 0
     wlans = filter(lambda x: x.startswith('wlan'), interfaces())
     return {'hardware':
                 { 'system': system()
                 , 'arch': machine()
                 , 'time': time.time()
                 , 'internet': hasInternet 
                 , 'wlans': list(wlans) 
                 , 'usage': {
                     'cpu': psutil.cpu_percent(interval=1, percpu=True),
                     'mem': psutil.virtual_memory().percent
                 }}}
コード例 #22
0
ファイル: internet.py プロジェクト: uvdl/camera-streamer
def ping(host):
    """
    Returns True if host (str) responds to a ping request.
    Remember that some hosts may not respond to a ping request even if the host name is valid.
    """
    # https://stackoverflow.com/questions/2953462/pinging-servers-in-python
    from platform import system as system_name  # Returns the system/OS name
    from os import system as system_call  # Execute a shell command

    # Ping parameters as function of OS
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"

    # Pinging
    return system_call("ping " + parameters + " " + host) == 0
コード例 #23
0
ファイル: generic.py プロジェクト: ovesnel/pyosupgrade
def ping(host):
    """
    https://stackoverflow.com/questions/2953462/pinging-servers-in-python

    Returns True if host (str) responds to a ping request.
    Remember that some hosts may not respond to a ping
    request even if the host name is valid.

    :param host:
    :return: bool
    """
    # Ping parameters as function of OS
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"
    # Pinging
    return system_call("ping " + parameters + " " + host + " > /dev/null") == 0
コード例 #24
0
def ping(host,count = 1):
    """
    :param host: ip address of host
    :param count: number of ping requests to send
    :returns: Returns True if host (str) responds to a ping request
    :rtype: bool
    ** Remember that some hosts may not respond to a ping request even if the host name is valid.
    """
    # TODO: validate IP address is valid

    # Ping parameters as function of OS
    funcname = GetFunctionName(ping)
    parameters = "-n {}".format(count) if system_name().lower() == "windows" else "-c {}".format(count)
    # Pinging
    return system_call("ping " + parameters + " " + host) == 0
コード例 #25
0
def ping(host):
    """Return True if host (str) responds to a ping request.

    Send a ping request to 'host' and return True if a response is received,
    False otherwise.
    Remember that some hosts may not respond to a ping request even if the host
    name is valid.

    Args:
        host: hostname (e.g. 192.168.1.2 or myhost.mydomain)

    Returns:
        True if host (str) responds to a ping request, False otherwise.
    """

    # Ping parameters as function of OS
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"

    # Pinging
    return system_call("ping " + parameters + " " + host + " > /dev/null") == 0
コード例 #26
0
ファイル: EFM.py プロジェクト: BrilliantSystems/T.I.M.E
def refresh():
    command = "cls" if system_name().lower() == "windows" else "clear"
    system_call(command)
コード例 #27
0
def ping(host):
    parameters = "-n 1" if system_name().lower() == "windows" else "-c 1"
    return system_call("ping " + parameters + " " + host + " > /dev/null") == 0
コード例 #28
0
def ping(host):
    #ping parameters depending on OS
    parameters = "-n 1 -w 3" if system_name().lower() == "windows" else "-c 1"
    #the ping command itself
    return system_call("ping " + parameters + " " + host + ">NUL") == 0
コード例 #29
0
def ping(host): 
    ping_param = "-n 1" if system_name().lower() == "windows" else "-c 1"
    return system_call("ping " + ping_param + " " + host) == 0
コード例 #30
0
def change_name(name):
    system_call('if [ -n "$TMUX" ]; then tmux rename-window -t${TMUX_PANE} "' +
                name + '";fi; if [ -n "$SECURECRT" ]; then echo -n "\033]2;"' +
                name + '"\007";fi')
コード例 #31
0
ファイル: sensors.py プロジェクト: jaquinonesg/SMA_exp
def ping(host):
    parameters = "-n 1" if system_name().lower()=="windows" else "-c 1"
    return system_call("ping " + parameters + " " + host) == 0