コード例 #1
0
ファイル: yaml_io.py プロジェクト: Italic-/maya-prefs
def dump(filename, obj, showError=True):
    try:
        makeWritable(filename)
        with open(filename, 'w') as f:
            f.write(yaml.dump(obj, default_flow_style=False))
    except IOError:
        if showError:
            message_box.exception('Cannot save YAML file:\n{}'.format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception('Unexpected error saving YAML file:\n{}'.format(filename))
        raise
コード例 #2
0
ファイル: json_io.py プロジェクト: Italic-/maya-prefs
def dump(filename, obj, showError=True):
    try:
        makeWritable(filename)
        with open(filename, "w") as f:
            json.dump(obj, f, sort_keys=True, indent=4, separators=(",", ": "))
    except IOError:
        if showError:
            message_box.exception("Cannot save JSON file:\n{}".format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception("Unexpected error saving JSON file:\n{}".format(filename))
        raise
コード例 #3
0
def load(filename, showError=True, alertNotExist=True):
    try:
        with open(filename, 'r') as f:
            obj = json.load(f)
    except IOError:
        if alertNotExist and not os.path.exists(filename):
            message_box.exception(
                'Cannot load JSON file. File does not exists:\n{}'.format(
                    filename))
        if showError:
            message_box.exception(
                'Cannot load JSON file:\n{}'.format(filename))
        raise
    except ValueError:
        if showError:
            message_box.exception(
                'Error parsing JSON file. Check syntax:\n{}'.format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception(
                'Unexpected error loading JSON file:\n{}'.format(filename))
        raise

    return obj
コード例 #4
0
def dump(filename, obj, showError=True):
    try:
        makeWritable(filename)
        with open(filename, 'w') as f:
            json.dump(obj, f, sort_keys=True, indent=4, separators=(',', ': '))
    except IOError:
        if showError:
            message_box.exception(
                'Cannot save JSON file:\n{}'.format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception(
                'Unexpected error saving JSON file:\n{}'.format(filename))
        raise
コード例 #5
0
ファイル: yaml_io.py プロジェクト: jubeyjose/maya-prefs
def dump(filename, obj, showError=True):
    try:
        makeWritable(filename)
        with open(filename, 'w') as f:
            f.write(yaml.dump(obj, default_flow_style=False))
    except IOError:
        if showError:
            message_box.exception(
                'Cannot save YAML file:\n{}'.format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception(
                'Unexpected error saving YAML file:\n{}'.format(filename))
        raise
コード例 #6
0
ファイル: yaml_io.py プロジェクト: Italic-/maya-prefs
def load(filename, showError=True, alertNotExist=True):
    try:
        with open(filename, 'r') as f:
            obj = yaml.load(f)
    except IOError:
        if alertNotExist and not os.path.exists(filename):
            message_box.exception('Cannot load YAML file. File does not exists:\n{}'.format(filename))
        if showError:
            message_box.exception('Cannot load YAML file:\n{}'.format(filename))
        raise
    except yaml.YAMLError:
        if showError:
            message_box.exception('Error parsing YAML file. Check syntax:\n{}'.format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception('Unexpected error loading YAML file:\n{}'.format(filename))
        raise

    return obj
コード例 #7
0
ファイル: json_io.py プロジェクト: Italic-/maya-prefs
def load(filename, showError=True, alertNotExist=True):
    try:
        with open(filename, "r") as f:
            obj = json.load(f)
    except IOError:
        if alertNotExist and not os.path.exists(filename):
            message_box.exception("Cannot load JSON file. File does not exists:\n{}".format(filename))
        if showError:
            message_box.exception("Cannot load JSON file:\n{}".format(filename))
        raise
    except ValueError:
        if showError:
            message_box.exception("Error parsing JSON file. Check syntax:\n{}".format(filename))
        raise
    except StandardError:
        if showError:
            message_box.exception("Unexpected error loading JSON file:\n{}".format(filename))
        raise

    return obj
コード例 #8
0
ファイル: command_desc.py プロジェクト: Italic-/maya-prefs
 def execute(self):
     try:
         meval(self.run)
     except StandardError:
         message_box.exception("Error during MEL command execution")
         raise
コード例 #9
0
ファイル: command_desc.py プロジェクト: Italic-/maya-prefs
 def execute(self):
     try:
         exec self.run
     except StandardError:
         message_box.exception("Error during Python command execution")
         raise