How to use the iotedgedev.utility.Utility.get_file_contents 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 / iotedgedev / modules.py View on Github external
elif template == "java":
            launch_json_file = "launch_java.json"
            replacements["%GROUP_ID%"] = group_id
        elif template == "nodejs":
            launch_json_file = "launch_node.json"
        elif template == "csharpfunction":
            launch_json_file = "launch_csharp.json"
            replacements["%APP_FOLDER%"] = "/app"
            is_function = True
        elif template == "python":
            launch_json_file = "launch_python.json"
            replacements["%APP_FOLDER%"] = "/app"

        if launch_json_file is not None:
            launch_json_file = os.path.join(os.path.split(__file__)[0], "template", launch_json_file)
            launch_json_content = Utility.get_file_contents(launch_json_file)
            for key, value in replacements.items():
                launch_json_content = launch_json_content.replace(key, value)
            if PY2:
                launch_json = commentjson.loads(six.binary_type(launch_json_content))
            else:
                launch_json = commentjson.loads(launch_json_content)
            if is_function and launch_json is not None and "configurations" in launch_json:
                # for Function modules, there shouldn't be launch config for local debug
                launch_json["configurations"] = list(filter(lambda x: x["request"] != "launch", launch_json["configurations"]))
            return launch_json
github Azure / iotedgedev / iotedgedev / dockercls.py View on Github external
def setup_registry_in_config(self, image_names):
        self.output.info(
            "Replacing 'mcr.microsoft.com/' with '{CONTAINER_REGISTRY_SERVER}/' in config files.")

        # Replace mcr.microsoft.com/ with ${CONTAINER_REGISTRY_SERVER}
        for config_file in self.utility.get_config_files():
            config_file_contents = Utility.get_file_contents(config_file)
            for image_name in image_names:
                config_file_contents = config_file_contents.replace(
                    "mcr.microsoft.com/" + image_name, "${CONTAINER_REGISTRY_SERVER}/" + image_name)

            with open(config_file, "w") as config_file_build:
                config_file_build.write(config_file_contents)
github Azure / iotedgedev / iotedgedev / deploymentmanifest.py View on Github external
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:
            if is_template:
                deployment_manifest_path = self.envvars.DEPLOYMENT_CONFIG_FILE_PATH
                if os.path.exists(deployment_manifest_path):
                    self.output.error('Deployment manifest template file "{0}" not found'.format(path))
                    if output.confirm('Would you like to make a copy of the deployment manifest file "{0}" as the deployment template file?'.format(deployment_manifest_path), default=True):
                        shutil.copyfile(deployment_manifest_path, path)
                        self.json = json.load(open(self.envvars.DEPLOYMENT_CONFIG_FILE_PATH))
                        self.envvars.save_envvar("DEPLOYMENT_CONFIG_TEMPLATE_FILE", path)
                else:
                    raise FileNotFoundError('Deployment manifest file "{0}" not found'.format(path))
            else:
                raise FileNotFoundError('Deployment manifest file "{0}" not found'.format(path))
github Azure / iotedgedev / iotedgedev / modules.py View on Github external
def _merge_launch_json(self, new_launch_json):
        vscode_dir = os.path.join(os.getcwd(), ".vscode")
        self.utility.ensure_dir(vscode_dir)
        launch_json_file = os.path.join(vscode_dir, "launch.json")
        if os.path.exists(launch_json_file):
            launch_json = commentjson.loads(Utility.get_file_contents(launch_json_file))
            launch_json['configurations'].extend(new_launch_json['configurations'])
            with open(launch_json_file, "w") as f:
                commentjson.dump(launch_json, f, indent=2)
        else:
            with open(launch_json_file, "w") as f:
                commentjson.dump(new_launch_json, f, indent=2)
github Azure / iotedgedev / iotedgedev / module.py View on Github external
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:
                raise KeyError("Error parsing {0} from module.json file : {1}".format(str(e), self.module_json_file))
            except IOError:
                raise IOError("Error loading module.json file : {0}".format(self.module_json_file))
        else:
            raise FileNotFoundError("No module.json file found. module.json file is required in the root of your module folder")
github Azure / iotedgedev / iotedgedev / utility.py View on Github external
def copy_template(self, src, dest=None, replacements=None, expandvars=True):
        """Read file at src, replace the keys in replacements with their values, optionally expand environment variables, and save to dest"""
        if dest is None:
            dest = src

        content = Utility.get_file_contents(src)

        if replacements:
            for key, value in replacements.items():
                content = content.replace(key, value)

        if expandvars:
            content = os.path.expandvars(content)

        with open(dest, "w") as dest_file:
            dest_file.write(content)