def execute(self):
        flags = gflags.FLAGS

        tree = find_dev_repo_obj()

        # Load component config
        comp_name = gflags.FLAGS.component
        comp = tree.get_component(comp_name)
        if comp is None:
            raise ActionAbort("Component does not exist: %s" % (comp_name))

        print "Updating", comp.path

        # Ask for new details
        if comp.config.source_type == ComponentConfig.SOURCE_DL_AND_UNPACK:
            comp.config.url = self.ask_simple("url",
                "Url to download",
                default=comp.config.url)

        comp.config.version = self.ask_simple('version',
            "Version for this URL",
            default=comp.config.version)

        comp.config.save()

        # Retrieve new files
        self.inform_user_of_action("Downloading component source")
        comp.retrieve_source()
    def execute(self):
        flags = gflags.FLAGS

        tree = find_dev_repo_obj()

        # Make sure components directory exists
        components_path = os.path.join(tree.path, 'components')
        if not os.path.exists(components_path):
            self.inform_user_of_action("Creating " + components_path)
            os.mkdir(components_path)

        name = self.ask_simple('name',
            "Name for this component",
            default = flags.name)

        path = os.path.join(components_path, name)
        if os.path.exists(path):
            raise ActionAbort("%s already exists" % (path))

        # Component type
        stype = self.ask_select('type',
            "How is this compontent obtained",
            options=[
                ComponentConfig.SOURCE_DL_AND_UNPACK,
                "git_clone",
                "custom_integrated"
                ])

        url = None
        if stype == ComponentConfig.SOURCE_DL_AND_UNPACK:
            url = self.ask_simple("url",
                "Url to download")
        else:
            raise NotImplementedError()

        version = self.ask_simple('version',
            "Current version of the component")

        MAP_TPLS = {
            'module': [
                (name, 'sites/all/modules/%s' % (name)),
                ],
            'theme': [
                (name, 'sites/all/themes/%s' % (name)),
                ],
            'library': [
                (name, 'sites/all/libraries/%s' % (name)),
                ],
            'base': [
                ('*', 'www/{1}'),
                ],
            'other': [
                ],
            }

        map_type = self.ask_select('map_type',
            "What type of component is this",
            options=['module', 'theme', 'library', 'base', 'other'])

        # -- Write package attribtes -----------------------------------------

        self.inform_user_of_action("Creating " + path)
        os.mkdir(path)

        config_path = os.path.join(path, 'component.ini')
        config = ComponentConfig(config_path)

        # Version
        config.version = version

        # Source
        config.source_type = stype
        if stype == ComponentConfig.SOURCE_DL_AND_UNPACK:
            config.url = url
        else:
            raise NotImplementedError()

        # Archive root folder
        if map_type == 'base':
            config.archive_root = '{name}-{ver}'
        elif map_type in ['module', 'theme', 'library']:
            config.archive_root = '{name}'
        else:
            config.archive_root = '.'


        # Mappings
        for pattern in MAP_TPLS[map_type]:
            config.add_mapping(ComponentFileMap(pattern[0], pattern[1]))

        # self.inform_user_of_action("Writing " + config_path)
        config.save()

        sub_path = os.path.join(path, 'source')
        self.inform_user_of_action("Creating " + sub_path)
        os.mkdir(sub_path)

        # Download
        self.inform_user_of_action("Downloading component source")
        tree.get_component(name).retrieve_source()