Exemplo n.º 1
0
    def __init__(self, parent=None, name=None, rel_id=None, mode="load", path=None,
            rate=None, reltype="Project", children=None, file=None, custom_path=True, **kwargs):
        
        super().__init__(rel_id=rel_id, reltype=reltype, name=name, 
            path=path, parent=parent, mode=mode, **kwargs)

        RelGlobals.set_project_instance(self)

        if name is None:
            self.rename()

        if path is None:
            p("Select a location for this project (folder will " + \
                "be created within selected location to house project files)")
            self.path = input_dir()
            os.makedirs(self.get_data_dir(), exist_ok=False)

        self.children = children if children is not None else []
        self.rate = rate
        self.arr = None
        if file is not None:
            self.read_file()

        if mode == "create":
            self.save()
Exemplo n.º 2
0
    def __init__(self, reldata_dir, proj_filename):
        section_head("Initializing Program")

        RelGlobals.set_rel_instance(self)

        self.relfile_path = join_path(reldata_dir, proj_filename)

        # set default output
        self.output = "Built-in Output"
        self.reltype = "Program"

        # maps name : path to that proj's datafile
        self.projects = self.read_proj_file()
        self.current_open_proj = None
Exemplo n.º 3
0
def process(obj):
    """
    process an object.
    'self.name', 'self.reltype' required.
    """
    section_head("Processing {0} '{1}'".format(obj.reltype, obj.name))

    while True:

        try:
            obj.process_message()
        except AttributeError:
            pass

        with style("cyan, bold"):
            print("\n{0} ".format(RelGlobals.get_process_num()), end="")
        p("What process to run on {0} '{1}'?".format(obj.reltype, obj.name),
          h=True,
          o="'o' to view process options",
          indent=0,
          hang=4,
          leading_newline=False)

        try:
            command = inpt(mode='split',
                           split_modes='arg',
                           help_callback=processes_help)
            if process_validate(command, obj):
                do_command(command, obj)
        except Cancel:
            return
Exemplo n.º 4
0
 def __init__(self,
              rel_id,
              reltype,
              name,
              path,
              parent,
              custom_path=False,
              **kwargs):
     super().__init__(**kwargs)
     self.parent = parent
     self.reltype = reltype
     self.name = name
     if path is None and not custom_path:
         if self.parent is not None:
             self.path = self.parent.get_data_dir()
         else:
             if Settings.is_debug():
                 err_mess(
                     "Warning: Setting relative path for {0} '{1}'".format(
                         self.reltype, self.name))
                 self.path = "./"
             else:
                 raise UnexpectedIssue("Path is None, with no parent")
         os.makedirs(self.get_data_dir(), exist_ok=True)
     else:
         self.path = path  # path not including object's own directory
     self.rel_id = rel_id if rel_id is not None else RelGlobals.get_next_id(
     )
     if path is not None and reltype != "Program":
         os.makedirs(self.get_data_dir(), exist_ok=True)
Exemplo n.º 5
0
    def _decode_one(self, val):

        if isinstance(val, (list, tuple)):
            for i in range(len(val)):
                val[i] = self._decode_one(val[i])
            return val

        elif isinstance(val, dict):
            return self._decoder(val)

        elif isinstance(val, str):
            if val.startswith("<PINTQUANT>"):
                val = re.sub("<PINTQUANT>", "", val)
                return Units.new(val)

            elif val.startswith("<RELATIVISM-PROGRAM>"):
                return RelGlobals.get_rel_instance()

            elif val.startswith("<RELOBJFILE>"):
                val = re.sub("<RELOBJFILE>", "", val)
                obj = self.load(val,
                                join_path(self.current_path, val, is_dir=True))
                self.need_parent.append(obj)
                return obj

            elif val.startswith("<RELSET>"):
                filename = re.sub("<RELSET>", "", val)
                fullpath = join_path(self.current_path,
                                     filename,
                                     ext=RelContainer.setfile_extension)
                with open(fullpath, "r") as f:
                    data = f.readlines()
                mod_name = data.pop(0).strip()
                clss_name = data.pop(0).strip()
                mod = importlib.import_module(mod_name)
                clss = getattr(mod, clss_name)

                val = json.loads("\n".join(data))
                if isinstance(val, dict):
                    for k, v in val.items():
                        val[k] = clss.load(clss, v)
                elif isinstance(val, (list, tuple)):
                    for i in range(len(val)):
                        val[i] = clss.load(clss, val[i])
                else:
                    raise UnexpectedIssue("this really shouldnt happen")

            elif val.startswith("<RELOBJ>"):
                val = re.sub("<RELOBJ>", "", val)
                ind = val.index(";")
                class_data, val = val[:ind], val[ind + 1:]
                mod_name, clss_name = class_data.split(",")
                mod = importlib.import_module(mod_name)
                clss = getattr(mod, clss_name)
                val = json.loads(val)
                return clss.load(clss, val)

        return val
Exemplo n.º 6
0
def log_err(message):
    """
    log err message string to RelGlobal.error_log
    """
    from src.globals import RelGlobals
    with open(RelGlobals.error_log(), "a") as log:
        if message[-1] != "\n":
            message += "\n"
        log.write(message)
Exemplo n.º 7
0
def critical_err_mess(e):
    """
    show 'something is broken' message and log error
    """
    from src.globals import RelGlobals
    with open(RelGlobals.error_log(), "a") as log:
        log.write("Critical Error {\n")
        traceback.print_exc(file=log)
        log.write("}\n")
    with style('red'):
        info_title("Critical Error, something appears to be broken:")
        info_line(str(e), indent=8)
        info_line("Please contact the developer")
        nl()
Exemplo n.º 8
0
MAX_SESS_LOGS = 20


from src.relativism import *
from src.debug import *
from src.output_and_prompting import *
from src.globals import RelGlobals, Settings, init_globals, save_globals

# TODO load extensions dynamically
# try:
#     from ext.autodrummer.autodrummer import *
# except:
#     pass


RelGlobals.set_error_log(ERROR_LOG)
RelGlobals.set_data_file(DATA_FILE)
RelGlobals.set_settings_file(SETTINGS_FILE)

# read globals and settings
init_globals()


with open(ERROR_LOG, "r") as log:

    # check multiple open sessions
    info_block("Checking logs...")
    lines = log.readlines()
    last = [i for i in lines if i.startswith("sess-start") or i.startswith("sess-end")][-1]
    kind, secs = last.strip().split("\t")
    secs = float(secs)
Exemplo n.º 9
0
 def get_bpm(context=None):
     return RelGlobals.get_project_instance().bpm(context)
Exemplo n.º 10
0
 def get_rate():
     return RelGlobals.get_project_instance().rate
Exemplo n.º 11
0
 def get_proj_path():
     return RelGlobals.get_project_instance().path