connectordb/_user.py
def export(self, directory):
        """Exports the ConnectorDB user into the given directory.
        The resulting export can be imported by using the import command(cdb.import(directory)),

        Note that Python cannot export passwords, since the REST API does
        not expose password hashes. Therefore, the imported user will have
        password same as username.

        The user export function is different than device and stream exports because
        it outputs a format compatible directly with connectorDB's import functionality:

            connectordb import < mydatabase > <directory >

        This also means that you can export multiple users into the same directory without issue
        """

        exportInfoFile = os.path.join(directory, "connectordb.json")
        if os.path.exists(directory):
            # Ensure that there is an export there already, and it is version 1
            if not os.path.exists(exportInfoFile):
                raise FileExistsError(
                    "The export directory already exsits, and is not a ConnectorDB export.")
            with open(exportInfoFile) as f:
                exportInfo = json.load(f)
            if exportInfo["Version"] != 1:
                raise ValueError(
                    "Could not export to directory: incompatible export versions.")
        else:
            # The folder doesn't exist. Make it.
            os.mkdir(directory)

            with open(exportInfoFile, "w") as f:
                json.dump(
                    {"Version": 1, "ConnectorDB": self.db.get("meta/version").text}, f)

        # Now we create the user directory
        udir = os.path.join(directory, self.name)
        os.mkdir(udir)

        # Write the user's info
        with open(os.path.join(udir, "user.json"), "w") as f:
            json.dump(self.data, f)

        # Now export the devices one by one
        for d in self.devices():
            d.export(os.path.join(udir, d.name))
def export(self, directory):
        """Exports the ConnectorDB user into the given directory.
        The resulting export can be imported by using the import command(cdb.import(directory)),

        Note that Python cannot export passwords, since the REST API does
        not expose password hashes. Therefore, the imported user will have
        password same as username.

        The user export function is different than device and stream exports because
        it outputs a format compatible directly with connectorDB's import functionality:

            connectordb import < mydatabase > <directory >

        This also means that you can export multiple users into the same directory without issue
        """

        exportInfoFile = os.path.join(directory, "connectordb.json")
        if os.path.exists(directory):
            # Ensure that there is an export there already, and it is version 1
            if not os.path.exists(exportInfoFile):
                raise FileExistsError(
                    "The export directory already exsits, and is not a ConnectorDB export.")
            with open(exportInfoFile) as f:
                exportInfo = json.load(f)
            if exportInfo["Version"] != 1:
                raise ValueError(
                    "Could not export to directory: incompatible export versions.")
        else:
            # The folder doesn't exist. Make it.
            os.mkdir(directory)

            with open(exportInfoFile, "w") as f:
                json.dump(
                    {"Version": 1, "ConnectorDB": self.db.get("meta/version").text}, f)

        # Now we create the user directory
        udir = os.path.join(directory, self.name)
        os.mkdir(udir)

        # Write the user's info
        with open(os.path.join(udir, "user.json"), "w") as f:
            json.dump(self.data, f)

        # Now export the devices one by one
        for d in self.devices():
            d.export(os.path.join(udir, d.name))
Exports the ConnectorDB user into the given directory.
        The resulting export can be imported by using the import command(cdb.import(directory)),

        Note that Python cannot export passwords, since the REST API does
        not expose password hashes. Therefore, the imported user will have
        password same as username.

        The user export function is different than device and stream exports because
        it outputs a format compatible directly with connectorDB's import functionality:

            connectordb import < mydatabase > <directory >

        This also means that you can export multiple users into the same directory without issue