Esempio n. 1
0
def handle(namespace, extra):
    APP_PARSER.add_argument('-t', '--no-toolbar', dest='toolbar', action='store_false', default=True)
    namespace = APP_PARSER.parse_args()

    dirname = os.path.abspath(os.path.expanduser(namespace.directory))

    app_slug = get_app_slug(namespace)

    config = get_config(namespace)

    def _ping_dev():
        url = '%sview/%s/%s/' % (
            config['tunnel_url'],
            config['username'],
            app_slug,
        )
        while 1:
            remote_call(config, 'start_dev',
                app_slug=app_slug,
                url=url,
                toolbar=namespace.toolbar,
            )
            time.sleep(240)  # Wait 4 Minutes

    ping_dev_thread = threading.Thread(target=_ping_dev)
    ping_dev_thread.daemon = True
    ping_dev_thread.start()

    func = create_monitor_thread(config, dirname, app_slug=app_slug)
    watch_change_thread = threading.Thread(target=func)
    watch_change_thread.daemon = True
    watch_change_thread.start()

    try:
        print 'Starting up development server'
        serve(config, dirname, app_slug)
    except KeyboardInterrupt:
        print '\nTearing down development server'
        remote_call(config, 'stop_dev', app_slug=app_slug)
Esempio n. 2
0
def handle(namespace, extra):
    namespace = APP_PARSER.parse_args()

    config = get_config(namespace)

    dirname = os.path.abspath(os.path.expanduser(namespace.directory))

    app_slug = get_app_slug(namespace)

    if not os.path.isdir(dirname):
        error_msg = 'Sorry, but %s is not a directory' % (dirname,)
        print >> sys.stderr, error_msg

    cwd = os.path.abspath(os.path.realpath(os.getcwd()))
    if not os.path.exists(os.path.join(cwd, 'clutch.plist')):
        print >> sys.stderr, 'Couldn\'t find clutch.plist, are you sure you\'re in an app directory?'
        sys.exit(1)

    tmp = StringIO()

    zip_context = contextlib.closing(
        zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED))

    with zip_context as z:
        paths = [dirname]
        while len(paths):
            hidden = '%s.' % (os.sep,)
            for root, dirs, files in os.walk(paths.pop()):
                if hidden in root:
                    continue
                for d in dirs:
                    normdir = os.path.join(root, d)
                    if os.path.islink(normdir):
                        paths.append(normdir)
                for fn in files:
                    if fn.startswith('.'):
                        continue
                    absfn = os.path.join(root, fn)
                    zfn = absfn[len(dirname) + len(os.sep):]  # XXX: relative path
                    z.write(absfn, zfn)

    resp = _post_zip_file(config, app_slug, tmp)
    del tmp

    print 'Uploaded new version: %s' % (resp,)
Esempio n. 3
0
def handle(namespace, extra):
    namespace = APP_PARSER.parse_args()

    config = get_config(namespace)

    dirname = os.path.abspath(os.path.expanduser(namespace.directory))

    app_slug = get_app_slug(namespace)

    if not os.path.isdir(dirname):
        error_msg = "Sorry, but %s is not a directory" % (dirname,)
        print >> sys.stderr, error_msg

    cwd = os.path.abspath(os.path.realpath(os.getcwd()))
    if not os.path.exists(os.path.join(cwd, "clutch.plist")):
        print >> sys.stderr, "Couldn't find clutch.plist, are you sure you're in an app directory?"
        sys.exit(1)

    tmp = StringIO()

    zip_context = contextlib.closing(zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED))

    with zip_context as z:
        paths = [dirname]
        while len(paths):
            hidden = "%s." % (os.sep,)
            for root, dirs, files in os.walk(paths.pop()):
                if hidden in root:
                    continue
                for d in dirs:
                    normdir = os.path.join(root, d)
                    if os.path.islink(normdir):
                        paths.append(normdir)
                for fn in files:
                    if fn.startswith("."):
                        continue
                    absfn = os.path.join(root, fn)
                    zfn = absfn[len(dirname) + len(os.sep) :]  # XXX: relative path
                    z.write(absfn, zfn)

    resp = _post_zip_file(config, app_slug, tmp)
    del tmp

    print "Uploaded new version: %s" % (resp,)