Exemple #1
0
def add_luna_callbacks():
    if Config.get(LunaVars.callback_licence, True):
        try:
            callbacks.remove_licence_popup_callback()
            Logger.info("Added file save licence callback")
        except RuntimeError:
            Logger.exception("Failed to add file save licence callback!")
Exemple #2
0
def create_file(path, data=""):
    try:
        with open(path, "w") as f:
            f.write(data)
    except IOError:
        Logger.exception("Failed to create file {0}".format(path))
        return None

    return path
Exemple #3
0
def load_pickle(path):
    try:
        with open(path, "r") as read_file:
            data = pickle.load(read_file)
    except IOError as e:
        Logger.exception("Failed to load file {0}".format(path), exc_info=e)
        return None

    return data
Exemple #4
0
def open_port(lang="python"):
    port = Config.get(LunaVars.command_port, default=7221)
    if not pm.commandPort("127.0.0.1:{0}".format(port), n=1, q=1):
        try:
            pm.commandPort(name="127.0.0.1:{0}".format(port),
                           stp="python",
                           echoOutput=True)
            Logger.info("Command port opened: Python - {0}".format(port))
        except Exception as e:
            Logger.exception("Failed to open command port", exc_info=e)
Exemple #5
0
def delete_oldest(directory, file_limit):
    all_files = [
        "{0}/{1}".format(directory, child) for child in os.listdir(directory)
    ]

    if file_limit and len(all_files) > file_limit:
        try:
            oldest_file = min(all_files, key=os.path.getctime)
            os.remove(oldest_file)
            return oldest_file
        except Exception as e:
            Logger.exception("Failed to delete file {0}".format(oldest_file),
                             exc_info=e)
            return None
Exemple #6
0
def load_json(path, string_data=False):
    try:
        with open(path, "r") as json_file:
            if string_data:
                data = json.loads(json_file)
            else:
                data = json.load(json_file)

    except IOError as e:
        Logger.exception("{0} is not a valid file path".format(path),
                         exc_info=e)
        return None
    except BaseException:
        Logger.exception("Failed to load file {0}".format(path), exc_info=e)
        return None

    return data  # type:dict
Exemple #7
0
def write_pickle(path, data):
    backup_data = {}
    status = 1

    backup_data = load_pickle(path)

    # Check if backup was saved
    if not status:
        return path, status

    try:
        with open(path, "w") as new_file:
            pickle.dump(data, new_file)
    except IOError:
        Logger.exception("Failed to saved file: {0}".format(path))
        pickle.dump(backup_data, new_file)
        Logger.warning("Reverted backup data for {0}".format(0))
        status = 0

    return path, status
Exemple #8
0
def copy_empty_scene(new_path):
    """Copy empty scenes from Luna's resource directory ot a given path. Scene version is based on current Maya version.

    Args:
        new_path (str): Full path to a new scene file location.

    Raises:
        IOError: If scene for selected maya version doesn't exist.
    """
    if os.path.isfile(new_path):
        return

    source_path = os.path.join(directories.EMPTY_SCENES_PATH,
                               "EmptyScene_Maya{0}.ma".format(pm.about(v=1)))
    Logger.debug("Copying file {0} to {1}".format(source_path, new_path))
    if not os.path.isfile(source_path):
        raise IOError
    try:
        shutil.copy2(source_path, new_path)
    except Exception:
        Logger.exception("Failed to copy scene {0}".format(source_path))
Exemple #9
0
def write_json(path, data={}, as_string=False, sort_keys=True):
    try:
        with open(path, "w") as json_file:
            if as_string:
                json_file.write(
                    json.dumps(data,
                               sort_keys=sort_keys,
                               indent=4,
                               separators=(",", ":")))
            else:
                json.dump(data, json_file, indent=4)

    except IOError as e:
        Logger.exception("{0} is not a valid file path".format(path),
                         exc_info=e)
        return None

    except BaseException:
        Logger.exception("Failed to write file {0}".format(path), exc_info=1)
        return None

    return path
Exemple #10
0
import pymel.core as pm
from functools import partial

from Luna import Logger
DEBUG_MODE = Logger.get_level() == 10
try:
    from Luna import Config
    from Luna.static import directories
    from Luna.interface.commands import tool_cmds
    from Luna.interface.commands import help_cmds
    from Luna.utils import devFn
    from Luna.utils import fileFn
    from Luna import TestVars
except Exception as e:
    Logger.exception("Failed to import modules", exc_info=e)

if DEBUG_MODE:
    try:
        reload(tool_cmds)
        reload(help_cmds)
        reload(devFn)
        Logger.debug("Menu - reloaded command modules")
    except ImportError:
        Logger.exception("Failed to reload command modules")


def _null_command(*args):
    pass


class MenuUtil:
Exemple #11
0
import os
from collections import deque
from datetime import datetime

from Luna import Logger
try:
    from Luna.utils import fileFn
    from Luna.utils import environFn
    from Luna import Config
    from Luna import ProjectVars
    from Luna.interface.hud import LunaHud
except Exception:
    Logger.exception("Failed to import modules")


class Project(object):
    """
    Base project class. Represents rigging project
    """
    TAG_FILE = "luna.proj"

    def __repr__(self):
        return "{0}({1}): {2}".format(self.name, self.path, self.meta_data)

    def __init__(self, path):
        self.path = path  # type: str

    @property
    def name(self):
        name = os.path.basename(self.path)  # type:str
        return name
Exemple #12
0
def build_luna_hud():
    try:
        LunaHud.create()
    except Exception:
        Logger.exception("Failed to create HUD")
Exemple #13
0
def build_luna_menu():
    try:
        LunaMenu.create()
    except Exception as e:
        Logger.exception("Failed to build Luna menu", exc_info=e)
Exemple #14
0
 def refresh(cls):
     try:
         pm.headsUpDisplay(cls.HUD_NAME, r=1)
     except BaseException:
         Logger.exception("Failed to refresh {0}".format(cls.HUD_NAME))