Пример #1
0
 def Run(self, args):
   if args.devsite_dir:
     walker_util.DevSiteGenerator(self._cli_power_users_only,
                                  args.devsite_dir).Walk(
                                      args.hidden, args.restrict)
   if args.help_text_dir:
     walker_util.HelpTextGenerator(
         self._cli_power_users_only, args.help_text_dir).Walk(args.hidden,
                                                              args.restrict)
   if args.html_dir:
     walker_util.HtmlGenerator(
         self._cli_power_users_only, args.html_dir).Walk(args.hidden,
                                                         args.restrict)
     tree = walker_util.CommandTreeGenerator(
         self._cli_power_users_only).Walk(args.hidden, args.restrict)
     with io.open(os.path.join(args.html_dir, '_menu_.html'), 'wt') as out:
       WriteHtmlMenu(tree, out)
     for file_name in _HELP_HTML_DATA_FILES:
       with io.open(os.path.join(args.html_dir, file_name), 'wb') as out:
         file_contents = pkg_resources.GetResource(
             'googlecloudsdk.api_lib.meta.help_html_data.', file_name)
         out.write(file_contents)
   if args.manpage_dir:
     walker_util.ManPageGenerator(
         self._cli_power_users_only, args.manpage_dir).Walk(args.hidden,
                                                            args.restrict)
   if args.update_help_text_dir:
     # The help text golden files are always ascii.
     console_attr.ResetConsoleAttr(encoding='ascii')
     changes = help_util.HelpTextUpdater(
         self._cli_power_users_only, args.update_help_text_dir,
         test=args.test).Update(args.restrict)
     if changes and args.test:
       raise HelpTextOutOfDateError('Help text files must be updated.')
Пример #2
0
def LoadTPUResourceSpecs(custom_help=None):
    """Read Yaml resource file and return a dict mapping name to resource spec."""
    resource_file_contents = pkg_resources.GetResource(TPU_YAML_RESOURCE_PATH,
                                                       'resources.yaml')
    if not resource_file_contents:
        raise calliope_exceptions.BadFileException(
            'Resources not found in path [{}]'.format(TPU_YAML_RESOURCE_PATH))

    resource_dict = yaml.load(resource_file_contents)
    resource_specs = []
    for resource_name in TPU_YAML_SPEC_TEMPLATE:
        spec = resource_dict.get(resource_name, None)
        if not spec:
            raise ValueError(
                'Resource spec [{}] not found in resource spec {}.yaml'.format(
                    resource_name, TPU_YAML_RESOURCE_PATH))

        # Don't modify template
        temp_spec = copy.deepcopy(TPU_YAML_SPEC_TEMPLATE[resource_name])

        temp_spec['spec'] = spec
        if custom_help and custom_help.get(resource_name):
            temp_spec['help_text'] = custom_help[resource_name]
        resource_specs.append(
            resource_arg_schema.YAMLResourceArgument.FromData(temp_spec))
    return resource_specs
Пример #3
0
    def FromPath(cls, resource_path):
        """Constructs a ResourceYAMLData from a standard resource_path.

    Args:
      resource_path: string, the dotted path of the resources.yaml file, e.g.
        iot.device or compute.instance.

    Returns:
      A ResourceYAMLData object.

    Raises:
      InvalidResourcePathError: invalid resource_path string.
    """
        match = re.search(_RESOURCE_PATH_PATTERN, resource_path)
        if not match:
            raise InvalidResourcePathError(
                'Invalid resource_path: [{}].'.format(resource_path))
        surface_name = match.group('surface_name')
        resource_name = match.group('resource_name')
        # Gets the directory name of the targeted YAML file.
        # Example: googlecloudsdk.command_lib.iot.
        dir_name = _RESOURCE_FILE_PREFIX + surface_name + '.'
        resource_file = pkg_resources.GetResource(dir_name,
                                                  _RESOURCE_FILE_NAME)
        # Loads the data from YAML file.
        resource_data = yaml.load(resource_file)[resource_name]
        return cls(resource_data)
Пример #4
0
 def Run(self, args):
     if args.devsite_dir:
         walker_util.DevSiteGenerator(self.cli, args.devsite_dir).Walk(
             args.hidden, args.restrict)
     if args.help_text_dir:
         walker_util.HelpTextGenerator(self.cli, args.help_text_dir).Walk(
             args.hidden, args.restrict)
     if args.html_dir:
         walker_util.HtmlGenerator(self.cli, args.html_dir).Walk(
             args.hidden, args.restrict)
         tree = walker_util.CommandTreeGenerator(self.cli).Walk(
             args.hidden, args.restrict)
         with open(os.path.join(args.html_dir, '_menu_.html'), 'w') as out:
             WriteHtmlMenu(tree, out)
         for file_name in _HELP_HTML_DATA_FILES:
             with open(os.path.join(args.html_dir, file_name), 'wb') as out:
                 file_contents = pkg_resources.GetResource(
                     'googlecloudsdk.api_lib.meta.help_html_data.',
                     file_name)
                 out.write(file_contents)
     if args.manpage_dir:
         walker_util.ManPageGenerator(self.cli, args.manpage_dir).Walk(
             args.hidden, args.restrict)
     if args.update_help_text_dir:
         changes = help_util.HelpTextUpdater(self.cli,
                                             args.update_help_text_dir,
                                             test=args.test).Update()
         if changes and args.test:
             raise HelpTextOutOfDateError(
                 'Help text files must be updated.')
Пример #5
0
  def Load():
    """Initializes the object with values from the config file.

    Returns:
      InstallationSpecificData: The loaded data.
    """
    data = json.loads(
        encoding.Decode(pkg_resources.GetResource(__name__, 'config.json')))
    return InstallationConfig(**data)
 def _GenerateHtmlNav(self, directory, cli, hidden, restrict):
   """Generates html nav files in directory."""
   tree = CommandTreeGenerator(cli).Walk(hidden, restrict)
   with files.FileWriter(os.path.join(directory, '_menu_.html')) as out:
     self.WriteHtmlMenu(tree, out)
   for file_name in _HELP_HTML_DATA_FILES:
     file_contents = pkg_resources.GetResource(
         'googlecloudsdk.api_lib.meta.help_html_data.', file_name)
     files.WriteBinaryFileContents(os.path.join(directory, file_name),
                                   file_contents)
 def GenerateHtmlNav(directory):
     """Generates html nav files in directory."""
     tree = walker_util.CommandTreeGenerator(
         self._cli_power_users_only).Walk(args.hidden, args.restrict)
     with files.FileWriter(os.path.join(directory,
                                        '_menu_.html')) as out:
         WriteHtmlMenu(tree, out)
     for file_name in _HELP_HTML_DATA_FILES:
         file_contents = pkg_resources.GetResource(
             'googlecloudsdk.api_lib.meta.help_html_data.', file_name)
         files.WriteBinaryFileContents(
             os.path.join(directory, file_name), file_contents)
Пример #8
0
  def Load():
    """Initializes the object with values from the config file.

    Returns:
      InstallationSpecificData: The loaded data.
    """
    data = json.loads(pkg_resources.GetResource(__name__, 'config.json'))

    # Python versions prior to 2.6.5 do not allow the keys in a kwargs dict to
    # be unicode strings.  The json module parses files as unicode.  We are not
    # using any unicode in the keys for our config properties so a simple
    # conversion to str is safe.
    non_unicode_data = dict([(str(k), v) for k, v in data.iteritems()])
    return InstallationConfig(**non_unicode_data)
Пример #9
0
    def __call__(self, environ, start_response):
        """WSGI Callable.

    Args:
        environ (Mapping[str, Any]): The WSGI environment.
        start_response (Callable[str, list]): The WSGI start_response callable.

    Returns:
        Iterable[bytes]: The response body.
    """
        start_response('200 OK', [('Content-type', 'text/html')])
        self.last_request_uri = wsgiref.util.request_uri(environ)
        query = self.last_request_uri.split('?', 1)[-1]
        query = dict(parse.parse_qsl(query))
        if 'code' in query:
            page = 'oauth2_landing.html'
        else:
            page = 'oauth2_landing_error.html'
        return [pkg_resources.GetResource(__name__, page)]
Пример #10
0
    def do_GET(self):
        """Handle a GET request.

    Parses the query parameters and prints a message
    if the flow has completed. Note that we can't detect
    if an error occurred.
    """
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        query = self.path.split('?', 1)[-1]
        query = dict(parse_qsl(query))
        self.server.query_params = query

        if 'code' in query:
            page = 'oauth2_landing.html'
        else:
            page = 'oauth2_landing_error.html'

        self.wfile.write(pkg_resources.GetResource(__name__, page))
Пример #11
0
 def Run(self, args):
     if args.devsite_dir:
         walker_util.DevSiteGenerator(self.cli, args.devsite_dir).Walk(
             args.hidden, args.restrict)
     if args.html_dir:
         walker_util.HtmlGenerator(self.cli, args.html_dir).Walk(
             args.hidden, args.restrict)
         tree = walker_util.CommandTreeGenerator(self.cli).Walk(
             args.hidden, args.restrict)
         with open(os.path.join(args.html_dir, '_menu_.html'), 'w') as out:
             WriteHtmlMenu(tree, out)
         for file_name in _HELP_HTML_DATA_FILES:
             with open(os.path.join(args.html_dir, file_name), 'wb') as out:
                 file_contents = pkg_resources.GetResource(
                     'googlecloudsdk.api_lib.meta.help_html_data.',
                     file_name)
                 out.write(file_contents)
     if args.manpage_dir:
         walker_util.ManPageGenerator(self.cli, args.manpage_dir).Walk(
             args.hidden, args.restrict)