# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
# def get_complex_cmd_output(cmd, stderr=STDOUT):
# def get_cmd_output_input_from_stdin(cmd, input_file):
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
# def get_exitcode_stdout_stderr(cmd):
# def execute_cmd(cmd):
# def execute_cmd_in_background(cmd):
# def get_process_list():
# def keep_alive(cmd):
# def is_process_running(pname):
# 
# Path: lib/process.py
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
#     """Execute a simple external command and return its exit status."""
#     args = shlex.split(cmd)
#     return call(args, stdout=PIPE, stderr=stderr)
# 
# Path: lib/web.py
# def get_page(url, debug=False, user_agent=True, timeout=MAX):
#     try:
#         with Timeout(timeout):
#             if user_agent:
#                 r = requests.get(url, headers=headers, timeout=timeout)
#             else:
#                 r = requests.get(url, timeout=timeout)
#             #
#             return r.text
#     except Timeout.Timeout:
#         if debug:
#             print("# timeout error", file=sys.stderr)
#         return None
#     except requests.exceptions.ConnectionError as e:
#         if debug:
#             print("#", e, file=sys.stderr)
#         return None


import json
import re
import socket
from lib import process
from lib.process import get_return_code_of_simple_cmd
from lib.web import get_page
from six.moves.urllib import error, request
#!/usr/bin/env python3

"""
Network-related stuff.

# from jplib import network
"""



URL = 'http://www.google.com'


def is_internet_on(method=1, debug=False):
    """Check if the Internet connection is on."""

    if method == 1:
        # At my current place we have a wifi that redirects to a login page,
        # so we always have a connection. That's why I check the content of
        # the fetched webpage.

# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
# def get_complex_cmd_output(cmd, stderr=STDOUT):
# def get_cmd_output_input_from_stdin(cmd, input_file):
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
# def get_exitcode_stdout_stderr(cmd):
# def execute_cmd(cmd):
# def execute_cmd_in_background(cmd):
# def get_process_list():
# def keep_alive(cmd):
# def is_process_running(pname):
# 
# Path: lib/process.py
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
#     """Execute a simple external command and return its exit status."""
#     args = shlex.split(cmd)
#     return call(args, stdout=PIPE, stderr=stderr)
# 
# Path: lib/web.py
# def get_page(url, debug=False, user_agent=True, timeout=MAX):
#     try:
#         with Timeout(timeout):
#             if user_agent:
#                 r = requests.get(url, headers=headers, timeout=timeout)
#             else:
#                 r = requests.get(url, timeout=timeout)
#             #
#             return r.text
#     except Timeout.Timeout:
#         if debug:
#             print("# timeout error", file=sys.stderr)
#         return None
#     except requests.exceptions.ConnectionError as e:
#         if debug:
#             print("#", e, file=sys.stderr)
#         return None


# Path: lib/network.py
import json
import re
import socket
from lib import process
from lib.process import get_return_code_of_simple_cmd
from lib.web import get_page
from six.moves.urllib import error, request

#!/usr/bin/env python3

"""
Network-related stuff.

# from jplib import network
"""



URL = 'http://www.google.com'


def is_internet_on(method=1, debug=False):
    """Check if the Internet connection is on."""

    if method == 1:
        # At my current place we have a wifi that redirects to a login page,
        # so we always have a connection. That's why I check the content of
        # the fetched webpage.

        text = get_page(URL, timeout=3, debug=debug)