#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# Setup a local backend, but just show the UI.  The user will interact with
# it and test manually.  Good for playing with the UI as you make changes,
# without futzing up your own gconf settings.

import base
import ldtp
import sys
import os
import tempfile

def test():
  version = None
  mtype = None
  tmpid = None
  sources = []
  dest = None
  size = None
  back = 'file'
  prog = None
  for arg in sys.argv[1:]:
    if arg == 'vfat':
      mtype = arg
    elif arg == 'ext3':
      mtype = arg
    elif arg == 'applet':
      prog = arg
    elif arg.startswith('id='):
      tmpid = arg.split('=', 1)[-1]
    elif arg.startswith('dup='):
      version = arg.split('=', 1)[-1]
    elif arg.startswith('source='):
      source = arg.split('=', 1)[-1]
      sources += [source]
    elif arg.startswith('size='):
      size = int(arg.split('=', 1)[-1])
    elif arg.startswith('back='):
      back = arg.split('=', 1)[-1]
    else:
      print "Unrecognized argument '%s'" % arg
      return 1
  
  if version is not None:
    os.environ['DEJA_DUP_TEST_VERSION'] = version
  if tmpid is not None:
    tmpdir = tempfile.gettempdir() + '/' + tmpid
    os.environ['DEJA_DUP_TEST_TMP'] = tmpdir
  if mtype is not None or size is not None:
    dest = base.create_mount(mtype=mtype, size=size)
  if sources:
    sources = map(lambda s: os.path.abspath(s), sources)
  
  base.setup(backend=back, dest=dest, sources=sources, start=False)
  
  if prog is None:
    base.start_deja_dup()  
    # Let user play with it for a while, maximum 2 hours
    if ldtp.waittillguinotexist('frmDéjàDup', guiTimeOut=60*60*2) == 0:
      base.quit()
  elif prog == 'applet':
    base.start_deja_dup_applet()
    ldtp.wait(60*60*2)

base.run(test)
