#!/usr/bin/env python

import sys
import os
import re
import string
import glob
import argparse
import subprocess
import tempfile
import shutil
import urllib

PLIST_BUDDY = "/usr/libexec/PlistBuddy"
MOBILE_PROVISIONS = "~/Library/MobileDevice/Provisioning Profiles/*.mobileprovision"
OUTPUT_IPA = "Output.ipa"
ICON_PNG = "Icon.png"
MANIFEST_PLIST = "manifest.plist"
INDEX_HTML = "index.html"
DEFAULT_DROPBOX_ROOT = "/AdHocBuilds"

tmpDir = None
log = None

class Logger:
    def __init__(self, quiet):
        self.quiet = quiet

    def e(self, *args):
        self._write(sys.stderr, args)

    def v(self, *args):
        if not self.quiet:
            self._write(sys.stdout, args)

    def o(self, *args):
        self._write(sys.stdout, args)

    def _write(self, stream, args):
        for a in args:
            stream.write(str(a))
        stream.write("\n")
        stream.flush()

def requireFile(path, errordesc, extraError = None):
    if not os.path.isfile(path):
        log.e("Error: ", errordesc, " not a file.")
        log.e("  path = ", path)
        if extraError is not None:
            log.e("  ", extraError)
        sys.exit(1)