Exemple #1
0
def main(ctx):

    """
    Run command, or start socket server.

    Normally this returns after running a single subcommand.
    If backgrounded, There is at most one server per projectdir
    document. The server remains in the working directory,
    and while running is used to resolve any calls. Iow. subsequent executions
    turn into UNIX domain socket clients in a transparent way, and the user
    command invocation is relayed via line-based protocol to the background
    server isntance.

    For projectdir document, which currently is 15-20kb, this setup has a
    minimal performance boost, while the Pd does not need
    to be loaded from and committed back to disk on each execution.

    """

    if ctx.opts.flags.background:
        localbg = __import__('local-bg')
        return localbg.serve(ctx, handlers, prerun=prerun)
    elif os.path.exists(ctx.opts.flags.address):
        localbg = __import__('local-bg')
        return localbg.query(ctx)
    elif 'exit' == ctx.opts.cmds[0]:
        print >>ctx.err, "No background process at %s" % ctx.opts.flags.address
        return 1
    else:
        diskdoc = os.path.expanduser(ctx.opts.flags.file)
        diskdata = yaml_load(open(diskdoc))
        func = ctx.opts.cmds[0]
        assert func in handlers
        return handlers[func](diskdata, ctx)
Exemple #2
0
def load_schema(path):
    path = path.replace('.', os.sep)+'.yml'
    try:
        meta = yaml_load(open(path))
    except Exception, e:
        print e
        raise Exception("Error loading %s from %s" % (path, os.getcwd()), e)
Exemple #3
0
def prerun(ctx, cmdline):
    global diskdata

    argv = cmdline.split(' ')
    ctx.opts = util.get_opts(ctx.usage, argv=argv)

    if not diskdata:
        diskdata = yaml_load(open(ctx.opts.flags.file))

    return [ diskdata ]
Exemple #4
0
 def parse(self, data):
     return yaml_load(StringIO(data))['list']
Exemple #5
0
 def parse_file(self, fn):
     data = yaml_load(open(fn))
     if data:
         return data['list']
     return []
Exemple #6
0
 def load_yaml(self, *args, **kwds):
     return yaml_load(*args, **kwds)
Exemple #7
0
 def from_user_path(Cls, fname):
     "Load and instantiate from YAML doc"
     diskdoc = os.path.expanduser(fname)
     diskdata = yaml_load(open(diskdoc))
     return Cls(diskdata)
Exemple #8
0
 def load_yaml(self, name, defaults=None):
     """
     Create and/or load and return YAML document.
     """
     p = self.get_yaml(name, defaults=defaults)
     return yaml_load(open(p))