コード例 #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)
コード例 #2
0
ファイル: mod_taxus_init.py プロジェクト: dotmpe/script-mpe
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)
コード例 #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 ]
コード例 #4
0
ファイル: magnet.py プロジェクト: dotmpe/script-mpe
 def parse(self, data):
     return yaml_load(StringIO(data))['list']
コード例 #5
0
ファイル: magnet.py プロジェクト: dotmpe/script-mpe
 def parse_file(self, fn):
     data = yaml_load(open(fn))
     if data:
         return data['list']
     return []
コード例 #6
0
ファイル: jsonlike.py プロジェクト: dotmpe/script-mpe
 def load_yaml(self, *args, **kwds):
     return yaml_load(*args, **kwds)
コード例 #7
0
ファイル: disk.py プロジェクト: dotmpe/script-mpe
 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)
コード例 #8
0
ファイル: js.py プロジェクト: dotmpe/script-mpe
 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))