Ejemplo n.º 1
0
    def get_directory_locations(self):

        c = self.context

        site = Site.Get(self.context)

        acre_dir = "~/acre"
        site_dir = "~/%s" % site.conf("id")

        name = raw_input(
            "Enter the directory where you want to install acre (default: %s):"
            % acre_dir)
        if not name:
            name = acre_dir

        c.options.acre_dir = os.path.expanduser(name.strip())

        name = raw_input(
            "Enter the directory where you want to install %s (default: %s):" %
            (site.conf("id"), site_dir))
        if not name:
            name = site_dir

        c.options.site_dir = os.path.expanduser(name.strip())

        site.set_site_dir(c.options.site_dir)
Ejemplo n.º 2
0
    def __call__(self):

        site = Site.Get(self.context)

        lib = None
        lib_app = App.Get(self.context, "lib")
        last_tag = lib_app.last_tag()
        if last_tag:
            lib = "//%s.%s.www.tags.svn.freebase-site.googlecode.dev" % (
                last_tag, "lib")
        else:
            lib = "//lib.www.trunk.svn.freebase-site.googlecode.dev"

        print '''
// WARNING: This is an auto-generated file by //trunk/scripts/sitedeploy.py.
// If you make changes to this file, please adjust ActionCreateRoutes.__call__ in there too.

var codebase = "%s";
var tags_codebase = "%s";

var environment_rules = {

    "labels" : {
        "lib": "%s",
        "default" : "//default.dev",
''' % (site.conf("acre_id_suffix_trunk"), site.conf("acre_id_suffix_tags"),
        lib)

        apps = site.apps()
        for i, app_key in enumerate(apps):

            if app_key == "lib":
                continue

            app = App.Get(self.context, app_key)
            last_tag = app.last_tag()

            if last_tag:
                print '        "%s": "//%s.%s" + tags_codebase%s' % (
                    app_key, last_tag, app_key, i < len(apps) - 1 and ","
                    or "")
            else:
                print '        "%s": "//%s" + codebase%s' % (
                    app_key, app_key, i < len(apps) - 1 and "," or "")

        print '''
    },

    "prefix" : []

};

acre.require(environment_rules.labels.lib + "/routing/router.sjs").route(environment_rules, this);
'''

        return True
Ejemplo n.º 3
0
    def __call__(self):
        c = self.context
        c.set_action("create_tag")

        if not (c.options.app and c.options.version):
            return c.error(
                'You have to specify a valid app and version to create a tag out of.'
            )

        site = Site.Get(c)

        if not site:
            return c.error(
                "Could not figure out location of site. You can specify --site_dir as an option, or run the script from within a site svn checkout directory structure to figure it out automatically."
            )

        acre = Acre.Get(c)

        if not acre:
            return c.error(
                "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk"
            )

        from_branch_app = App.Get(c, c.options.app, c.options.version)
        tag_app = from_branch_app.create_tag()

        #if not no_static:
        r = ActionStatic(c)(app=tag_app)
        if not r:
            tag_app.remove_from_svn()
            return c.error(
                'Failed to create static files for "%s" - tag removed from SVN.'
                % tag_app)

        c.log('Created "%s"' % tag_app, color=c.BLUE)

        return True
Ejemplo n.º 4
0
    def __call__(self, app=None):

        c = self.context

        site = Site.Get(c)

        acre = Acre.Get(c)
        if not acre:
            return c.error("Can't continue without an acre instance.")

        if not (acre.is_running() or
                (acre.build(target='devel',
                            config_dir="%s/appengine-config" % site.site_dir)
                 and acre.start())):
            return c.error(
                "There was an error starting acre - cannot generate static files without a running acre instance."
            )

        c.set_acre(acre)

        success = c.googlecode_login()

        if not success:
            return c.error(
                'You must provide valid google code credentials to complete this operation.'
            )

        if not app:
            app = c.current_app

        if not app.tag:
            return c.error('You can only create static files for app tags')

        r = app.statify()

        return r
Ejemplo n.º 5
0
    def __call__(self):

        c = self.context
        if not c.options.site_dir:
            raise FatalException(
                "You must specify a directory to install the site in with --site_dir."
            )

        site = Site.Get(c)

        acre = Acre.Get(c)

        if not acre:
            return c.error(
                "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk"
            )

        success = c.googlecode_login()
        if not success:
            return c.error(
                'You must provide valid google code credentials to complete this operation.'
            )

        self.site_checkout = c.options.acre_dir + '/webapp/WEB-INF/scripts/%s/%s' % (
            site.conf("repository"), site.conf("id"))

        try:
            os.makedirs(self.site_checkout)
            self.site_checkout += '/svn'
        except:
            return c.error(
                'The directory %s already exists, or unable to create directory.'
                % self.site_checkout)

        r = site.checkout(self.site_checkout)

        if not r:
            return False

        r = c.symlink(self.site_checkout, site.site_dir)

        config_dir = "%s/appengine-config" % site.site_dir

        r = Acre.Get(c).build(target="devel", config_dir=config_dir)
        if not r:
            return c.error('Failed to build acre under %s' %
                           c.options.acre_dir)

        c.log("*" * 65)
        c.log("")
        c.log("In order to run the site:")
        c.log(
            "\t1. Run the acre server: \n cd %s; ./acre -c devel -d %s appengine-run"
            % (c.options.acre_dir, config_dir))
        c.log("\t2. Visit http://devel.sandbox-freebase.com:%s" %
              c.options.acre_port)
        c.log("%s is now installed in %s" % (site.conf("id"), site.site_dir))
        c.log("")
        c.log("*" * 65)

        return True
Ejemplo n.º 6
0
    def __call__(self):

        c = self.context
        site = Site.Get(c)
        acre = Acre.Get(c)

        config, app_id, app_version = Site.ResolveConfig(
            c, c.options.config, c.options.site_dir, c.options.host)

        if not site:
            return c.error(
                "Could not figure out location of site. You can specify --site_dir as an option, or run the script from within a site svn checkout directory structure to figure it out automatically."
            )

        if not acre:
            return c.error(
                "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk"
            )

        if not config:
            return c.error(
                "You have to specify an acre build target with -c e.g. -c sandbox-freebasesite or a host with --host e.g. --host dev.sandbox-freebase.com"
            )

        (r,
         result) = acre.build(config,
                              config_dir="%s/appengine-config" % site.site_dir,
                              war=True)

        if not r:
            return c.error("Acre failed to build, aborting.")

        if not c.options.nosite:
            status = acre.start(war=True)

            if not status:
                return c.error(
                    'Could not start new acre war bundle under appengine development server, aborting deployment'
                )

        c.log("\nDeployment Summary " + "*" * 45 + "\n", color=c.BLUE)
        c.log("  Config: %s" % config, color=c.BLUE)
        c.log("  Deployed URL: http://%s" % acre.site_host(True), color=c.BLUE)
        if app_version is None:
            c.log("  AppEngine URL: http://%s.appspot.com/" % app_id,
                  color=c.BLUE)
        else:
            c.log("  AppEngine URL: http://%s.%s.appspot.com/" %
                  (app_version, app_id),
                  color=c.BLUE)
        c.log(
            "  AppEngine Dashboard: https://appengine.google.com/dashboard?&app_id=%s\n"
            % app_id,
            color=c.BLUE)
        c.log("*" * 65 + "\n", color=c.BLUE)

        for directory in acre.site_dir(war=True):
            if os.path.isdir(directory + '/googlecode'):
                shutil.rmtree(directory + '/googlecode')

        if not c.options.nosite:
            apps = acre.fs_routed_apps()

            if not len(apps):
                raise FatalException(
                    "Something went wrong, there are no apps to bundle with Acre, aborting!"
                )

            for app in apps:
                result = app.copy_to_acre_dir(war=True)
                if not result:
                    c.error(
                        'Failed to copy %s to app-engine bundle, continuing with other apps...'
                        % app)

            # By default, push the environments app too unless --failover was specified.
            if not c.options.failover:
                acre.bundle_environments()

            c.log('The following apps were bundled:\n')
            for app in sorted(apps):
                c.log('\t%s' % app)

        acre.bundle_static_files()

        c.log('\nStarting deployment...', color=c.BLUE)
        if not acre.deploy(target=config):
            return c.error('Deployment failed.')

        if c.options.failover:
            c.log('\nStarting deployment of failover version...', color=c.BLUE)
            r = acre.prepare_failover()

            if not r:
                return c.error(
                    'Failed to prepare failover version of acre, aborting.')

            acre.bundle_environments()

            if not acre.deploy(config):
                return c.error('Failover deployment failed.')

        return True
Ejemplo n.º 7
0
def main():

    # OPTION PARSING

    valid_actions = [
        ("setup_acre", "create a local acre instance", ActionSetupAcre),
        ("setup_site", "create a local site instance", ActionSetupSite),
        ("setup", "\tsetup acre and freebase-site and link them", ActionSetup),
        ("deploy_acre", "deploy an acre instance to production app-engine",
         ActionDeployAcre),
        ("setup_dns", "setup freebase site dns for your host",
         ActionSetupSimpleDNS),
        ("setup_wildcard_dns",
         "setup wildcard dns for your host - Mac OS X only",
         ActionSetupWildcardDNS),
        ("info", "provide information on all apps or a specific app",
         ActionInfo),
        ("create_branch", "creates a branch of your app",
         ActionCreateAppBranch),
        ("create_tag", "creates a tag of your app", ActionCreateAppTag),
        ("create_static",
         "creates a static bundle and writes it to the provided tag",
         ActionStatic), ("speedtest", "run a speedtest", ActionSpeedTest),
        ("getids",
         "get freebase mids for a given type - useful for speedtests",
         ActionGetIds),
        ("listapps", "get a list of apps for this site", ActionListApps),
        ("create_routes",
         "create the routes configuration that will point to the last tag of every app",
         ActionCreateRoutes), ("test", "\ttest", ActionTest)
    ]

    usage = """%prog action [options]
\nActions:
"""
    usage += "\n".join(["\t%s\t%s" % a[:2] for a in valid_actions])

    parser = OptionParser(usage=usage)
    parser.add_option("-u",
                      "--user",
                      dest="user",
                      help="google code username - e.g. [email protected]")
    parser.add_option("-p",
                      "--password",
                      dest="password",
                      help="google code password")
    parser.add_option("-b",
                      "--verbose",
                      dest="verbose",
                      action="store_true",
                      default=False,
                      help="verbose mode will print out more debugging output")
    parser.add_option("",
                      "--acre_dir",
                      dest="acre_dir",
                      default=None,
                      help="the local acre directory")
    parser.add_option(
        "",
        "--acre_version",
        dest="acre_version",
        default=None,
        help=
        "an svn version of acre - either 'trunk' or a branch number like '34'")
    parser.add_option(
        "",
        "--acre_host",
        dest="acre_host",
        default="z",
        help="the hostname that you will use to address this acre installation"
    )
    parser.add_option("",
                      "--site_dir",
                      dest="site_dir",
                      default=None,
                      help="the local site directory")
    parser.add_option("",
                      "--acre_port",
                      dest="acre_port",
                      default=8115,
                      help="the port you want to serve acre from")
    parser.add_option(
        "-c",
        "--config",
        dest="config",
        help="acre configuration target - e.g. sandbox-freebasesite or devel")
    parser.add_option(
        "-v",
        "--version",
        dest="version",
        default=None,
        help=
        "a version of the app - e.g. 12 - use 'latest' to auto-detect the last version branched"
    )
    parser.add_option("-t",
                      "--tag",
                      dest="tag",
                      default=None,
                      help="a tag of the app - e.g. 12b")
    parser.add_option(
        "-a",
        "--app",
        dest="app",
        default=None,
        help=
        "an app id - e.g. /user/namesbc/mysuperapp or an app key under /freebase/site - e.g. homepage"
    )
    parser.add_option(
        "-d",
        "--dependency",
        dest="dependency",
        default="latest",
        help=
        "the version of the dependency app you want to tie this app branch to - use 'latest' to tie to last branched version"
    )
    parser.add_option(
        "",
        "--failover",
        dest="failover",
        action="store_true",
        default=False,
        help="will also deploy acre to the failover version of appengine")
    parser.add_option(
        "",
        "--nosite",
        dest="nosite",
        action="store_true",
        default=False,
        help=
        "will not bundle freebase site with acre when deploying to appengine")
    parser.add_option("-s",
                      "--site",
                      dest="site",
                      default="freebase-site",
                      help="the site you want to work on - one of %s" %
                      ",".join(Site._sites.keys()))
    parser.add_option(
        "",
        "--prevent_overwrite",
        dest="prevent_overwrite",
        action="store_true",
        default=False,
        help="avoid copying svn checkouts if the directory already exists")

    #speedtest options

    parser.add_option("",
                      "--page",
                      dest="page",
                      default=None,
                      help="speedtest: the page you are testing")
    parser.add_option("",
                      "--test",
                      dest="test",
                      default=None,
                      help="speedtest: the test you want to run")
    parser.add_option("",
                      "--repeat",
                      dest="repeat",
                      default=10,
                      help="speedtest: number of times the page will be hit",
                      type="int")
    parser.add_option("",
                      "--host",
                      dest="host",
                      default=None,
                      help="host to hit - just the domain name")
    parser.add_option("",
                      "--concurrent",
                      dest="concurrent",
                      default=1,
                      help="speedtest: number of concurrent clients",
                      type="int")
    parser.add_option("",
                      "--list",
                      dest="list",
                      action="store_true",
                      default=False,
                      help="speedtest: list pages and tests")
    parser.add_option("",
                      "--type",
                      dest="type",
                      default="/type/type",
                      help="freebase type id")
    parser.add_option("",
                      "--cost",
                      dest="cost",
                      default=ActionSpeedTest.x_cost_default,
                      help="x-metaweb-cost verbosity: %s" %
                      "\n".join(ActionSpeedTest.x_labels_groups.keys()))

    # Parse the arguments.
    (options, args) = parser.parse_args()

    # Figure out the action - one action per call.

    # There was no action specified here.
    if not len(args) or args[0] not in [a[0] for a in valid_actions]:
        parser.error('You did not provide a valid action')
        exit(-1)

    action = args[0]
    context = Context(options)
    context.set_action(action)

    for valid_action in valid_actions:
        if action == valid_action[0]:
            action_class = valid_action[2]

    def run(action_class, context):
        """Run an action given the context."""
        context.start_time = datetime.datetime.now()
        result = None

        try:
            result = action_class(context)()

        finally:
            t2 = datetime.datetime.now()

            if not result:
                context.error(
                    'FAILED: action %s failed (%s)' %
                    (action, context.duration_human(t2 - context.start_time)))
            else:
                context.log(
                    'SUCCESS: action %s ended succesfully (%s)' %
                    (action, context.duration_human(t2 - context.start_time)),
                    color=context.GREEN)

            context.set_action(action)

        return True

    result = None
    results = []
    context.start_time = datetime.datetime.now()
    # Loop through each app, resolve version/lib from arguments and run the action with that app.

    try:
        if options.app:
            apps = options.app.split(',')
            if apps[0] == "all":
                apps = Site.Get(context).apps()

            for i, app in enumerate(apps):
                options.app = app
                context.set_app(
                    App.Get(context, app, options.version, options.tag))
                result = run(action_class, context)
                results.append(result)

        else:
            result = run(action_class, context)
            results.append(result)

    except KeyboardInterrupt:
        context.error("Aborted by user.")
    except FatalException as ex:
        context.error(ex.msg)
    finally:
        t2 = datetime.datetime.now()
        acre = Acre.Get(context, existing=True)
        if acre:
            acre.stop()

    if not result or False in results:
        n = len([x for x in results if not x])
        context.error(
            'FAILED: action %s failed (%s)' %
            (action, context.duration_human(t2 - context.start_time)))
        if n > 1:
            context.error('%s action%s failed.' % (n, n > 1 and 's' or ''))

    for reminder in context.reminders:
        context.log(reminder, 'reminder', color=context.RED)
Ejemplo n.º 8
0
 def __call__(self):
     print ",".join(Site.Get(self.context).apps())
     return True