def create_syncdaemon(username, procnum, homedir, pidfile):
    """Creates a SD with its DBus."""
    prefix = 'Create_syncdaemon:'
    # start dbus
    debug(prefix, 'Starting DBus...')
    (dbus_pid, dbus_address) = start_DBus()
    debug(prefix, 'DBus started with (dbus_pid, dbus_address):', dbus_pid,
          dbus_address)

    # run the client
    env = dict(DBUS_SESSION_BUS_ADDRESS=dbus_address,
               PYTHONPATH=LIB_DIR,
               XDG_CACHE_HOME="tmp/xdg_cache%d" % procnum)
    value = (dbus_pid, dbus_address)
    debug(prefix, "Putting in pidfile %s values %s" % (pidfile, value))
    with open(pidfile, 'w') as f:
        f.write(' '.join(map(str, value)))
        f.write('\n')

    debug(prefix, "Launching SD with dbus", dbus_address)
    dev_launcher.launch("sourcecode/ubuntuone-client/bin/ubuntuone-syncdaemon",
                        username,
                        params=("--send_events_over_dbus",
                                "--udf_autosubscribe=true"),
                        environ=env,
                        homedir=homedir,
                        verbose=True)
def create_syncdaemon(username, procnum, homedir, pidfile):
    """Creates a SD with its DBus."""
    prefix = 'Create_syncdaemon:'
    # start dbus
    debug(prefix, 'Starting DBus...')
    (dbus_pid, dbus_address) = start_DBus()
    debug(prefix, 'DBus started with (dbus_pid, dbus_address):',
          dbus_pid, dbus_address)

    # run the client
    env = dict(DBUS_SESSION_BUS_ADDRESS=dbus_address,
               PYTHONPATH=LIB_DIR,
               XDG_CACHE_HOME="tmp/xdg_cache%d" % procnum)
    value = (dbus_pid, dbus_address)
    debug(prefix, "Putting in pidfile %s values %s" % (pidfile, value))
    with open(pidfile, 'w') as f:
        f.write(' '.join(map(str, value)))
        f.write('\n')

    debug(prefix, "Launching SD with dbus", dbus_address)
    dev_launcher.launch(
        os.path.join(CLIENT_DIR, 'bin', 'ubuntuone-syncdaemon'),
        username,
        params=("--send_events_over_dbus", "--udf_autosubscribe=true"),
        environ=env, homedir=homedir, verbose=True)
def main(args):
    """run devlauncher"""
    from optparse import OptionParser
    if len(args) < 3:
        print usage()
        return

    parser = OptionParser(usage=usage())
    parser.add_option('-p',
                      '--port',
                      dest='port',
                      help="The port to where connect")
    parser.add_option('-t',
                      '--host',
                      dest='host',
                      help="The host to where connect")
    parser.add_option('-a', '--auth', dest='auth', help="Auth data")
    parser.add_option('-m',
                      '--machine',
                      dest='machine',
                      help="Machine number (to have multiple launchers with "
                      "the same user)")

    # check to see if we have extra params for the command to execute
    if "--" in args:
        pos = args.index("--")
        params = args[pos + 1:]
        args = args[:pos]
    else:
        params = []

    (options, pargs) = parser.parse_args(args[1:])
    progname, username = pargs
    if options.machine:
        machine_suffix = "_" + options.machine
    else:
        machine_suffix = None

    lib_dir = _pythonpath.get_lib_dir()
    d = dict(
        PYTHONPATH=lib_dir,
        XDG_CACHE_HOME="tmp/xdg_cache",
    )

    dev_launcher.launch(progname,
                        username,
                        params,
                        environ=d,
                        verbose=True,
                        machine_suffix=machine_suffix,
                        host=options.host,
                        api_port=options.port,
                        auth_data=options.auth)
def main(args):
    """run devlauncher"""
    from optparse import OptionParser
    if len(args) < 3:
        print usage()
        return

    parser = OptionParser(usage=usage())
    parser.add_option('-p', '--port', dest='port',
                      help="The port to where connect")
    parser.add_option('-t', '--host', dest='host',
                      help="The host to where connect")
    parser.add_option('-a', '--auth', dest='auth',
                      help="Auth data")
    parser.add_option('-m', '--machine', dest='machine',
                      help="Machine number (to have multiple launchers with "
                      "the same user)")

    # check to see if we have extra params for the command to execute
    if "--" in args:
        pos = args.index("--")
        params = args[pos + 1:]
        args = args[:pos]
    else:
        params = []

    (options, pargs) = parser.parse_args(args[1:])
    progname, username = pargs
    if options.machine:
        machine_suffix = "_" + options.machine
    else:
        machine_suffix = None

    lib_dir = _pythonpath.get_lib_dir()
    d = dict(
        PYTHONPATH=lib_dir,
        XDG_CACHE_HOME="tmp/xdg_cache",
    )

    dev_launcher.launch(progname, username, params, environ=d, verbose=True,
                        machine_suffix=machine_suffix, host=options.host,
                        api_port=options.port, auth_data=options.auth)