How to use the iotedgedev.compat.PY2 function in iotedgedev

To help you get started, we’ve selected a few iotedgedev examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / iotedgedev / tests / test_envvars.py View on Github external
def test_envvar_clean():
    output = Output()
    envvars = EnvVars(output)
    envvar_clean_name = u"IOTEDGEDEV_ENVVAR_CLEAN_TEST"
    os.environ[envvar_clean_name] = u"test unicode string"

    envvars.clean()

    if PY2:
        assert isinstance(os.environ[envvar_clean_name], str)
github Azure / iotedgedev / iotedgedev / simulator.py View on Github external
import os

from .compat import PY2
from .modules import Modules
from .utility import Utility

if PY2:
    from .compat import FileNotFoundError


class Simulator:
    def __init__(self, envvars, output):
        self.envvars = envvars
        self.output = output
        self.utility = Utility(self.envvars, self.output)

    def setup(self, gateway_host, iothub_connection_string=""):
        self.output.header("Setting Up IoT Edge Simulator")
        self.envvars.verify_envvar_has_val("DEVICE_CONNECTION_STRING", self.envvars.DEVICE_CONNECTION_STRING)

        cmd = ["iotedgehubdev", "setup", "-c", self.envvars.DEVICE_CONNECTION_STRING]
        if gateway_host:
            cmd.extend(["-g", gateway_host])
github Azure / iotedgedev / iotedgedev / envvars.py View on Github external
def clean(self):
        """docker-py had py2 issues with shelling out to docker api if unicode characters are in any environment variable. This will convert to utf-8 if py2."""

        if PY2:
            environment = os.environ.copy()

            clean_enviro = {}

            for k in environment:
                key = k
                if isinstance(key, unicode):
                    key = key.encode('utf-8')

                if isinstance(environment[k], unicode):
                    environment[k] = environment[k].encode('utf-8')

                clean_enviro[key] = environment[k]

            os.environ = clean_enviro
github Azure / iotedgedev / iotedgedev / azurecli.py View on Github external
import json
import os
import signal
import subprocess
import sys
from io import StringIO
from threading import Thread, Timer

from azure.cli.core import get_default_cli
from fstrings import f
from six.moves.queue import Empty, Queue

from . import telemetry
from .compat import PY2

if PY2:
    from .compat import FileNotFoundError

output_io_cls = StringIO


def get_query_argument_for_id_and_name(token):
    return "[?starts_with(@.id,'{0}') || contains(@.name,'{1}')]".format(token.lower(), token)


class AzureCli:
    def __init__(self,  output, envvars, cli=get_default_cli()):
        self.output = output
        self.envvars = envvars
        self.az_cli = cli
        self.process = None
        self._proc_terminated = False
github Azure / iotedgedev / iotedgedev / utility.py View on Github external
import fnmatch
import json
import os
import subprocess
from base64 import b64decode, b64encode
from hashlib import sha256
from hmac import HMAC
from time import time

from six.moves.urllib.parse import quote, urlencode

from .compat import PY2
from .constants import Constants

if PY2:
    from .compat import FileNotFoundError


class Utility:
    def __init__(self, envvars, output):
        self.envvars = envvars
        self.output = output

    def exe_proc(self, params, shell=False, cwd=None, suppress_out=False):
        proc = subprocess.Popen(
            params, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, cwd=cwd)

        stdout_data, stderr_data = proc.communicate()
        if not suppress_out and stdout_data != "":
            self.output.procout(self.decode(stdout_data))
github Azure / iotedgedev / iotedgedev / modules.py View on Github external
import six
from six import BytesIO
from six.moves.urllib.request import urlopen

from . import telemetry
from .buildoptionsparser import BuildOptionsParser
from .buildprofile import BuildProfile
from .compat import PY2
from .deploymentmanifest import DeploymentManifest
from .dockercls import Docker
from .dotnet import DotNet
from .module import Module
from .utility import Utility
from .constants import Constants

if PY2:
    from .compat import FileNotFoundError


class Modules:
    def __init__(self, envvars, output):
        self.envvars = envvars
        self.output = output
        self.utility = Utility(self.envvars, self.output)

    def add(self, name, template, group_id):
        self.output.header("ADDING MODULE {0}".format(name))

        deployment_manifest = DeploymentManifest(self.envvars, self.output, self.utility, self.envvars.DEPLOYMENT_CONFIG_TEMPLATE_FILE, True)

        cwd = self.envvars.MODULES_PATH
        self.utility.ensure_dir(cwd)
github Azure / iotedgedev / iotedgedev / module.py View on Github external
import json
import os

from .compat import PY2
from .utility import Utility

if PY2:
    from .compat import FileNotFoundError


class Module(object):
    def __init__(self, envvars, utility, module_dir):
        self.utility = utility
        self.module_dir = module_dir
        self.module_json_file = os.path.join(self.module_dir, "module.json")
        self.file_json_content = None
        self.load_module_json()

    def load_module_json(self):
        if os.path.exists(self.module_json_file):
            try:
                self.file_json_content = json.loads(Utility.get_file_contents(self.module_json_file, expandvars=True))
            except KeyError as e:
github Azure / iotedgedev / iotedgedev / deploymentmanifest.py View on Github external
"""

import json
import os
import re
import shutil

import six
import jsonschema
from six.moves.urllib.request import urlopen

from .compat import PY2
from .utility import Utility
from .constants import Constants

if PY2:
    from .compat import FileNotFoundError

TWIN_VALUE_MAX_SIZE = 512
TWIN_VALUE_MAX_CHUNKS = 8


class DeploymentManifest:
    def __init__(self, envvars, output, utility, path, is_template, expand_vars=True):
        self.envvars = envvars
        self.utility = utility
        self.output = output
        try:
            self.path = path
            self.is_template = is_template
            self.json = json.loads(Utility.get_file_contents(path, expandvars=expand_vars))
        except FileNotFoundError: