def testOverride(self):
     properties12 = properties_file.PropertiesFile(
         [self.properties1_file, self.properties2_file])
     self.assertEqual(properties12.Get('core', 'funtimes'), 'are here')
     self.assertEqual(properties12.Get('core', 'john'), 'meh')
     self.assertEqual(properties12.Get('core', 'mark'), 'so so')
     self.assertEqual(properties12.Get('core', 'rajeev'), 'awesome')
예제 #2
0
 def CheckProperty(self, prop, scope, value=None):
     prop_file = (named_configs.ConfigurationStore.ActiveConfig().file_path
                  if scope == properties.Scope.USER else
                  config.Paths().installation_properties_path)
     props = properties_file.PropertiesFile([prop_file])
     set_value = props.Get(prop.section, prop.name)
     self.assertEqual(set_value, value)
예제 #3
0
 def AssertPropertySet(self, prop, value, scope):
     section, name = properties.ParsePropertyString(prop)
     if scope == properties.Scope.USER:
         values = (named_configs.ConfigurationStore.AllConfigs()
                   ['default'].GetProperties())
     else:
         values = (properties_file.PropertiesFile(
             [config.Paths().installation_properties_path]).AllProperties())
     self.assertEqual(value, values.get(section, {}).get(name, None))
 def testMultiSection(self):
     properties123 = properties_file.PropertiesFile([
         self.properties1_file, self.properties2_file, self.properties3_file
     ])
     self.assertEqual(properties123.Get('core', 'mark'),
                      "ok you're cool too")
     self.assertEqual(properties123.Get('compute', 'project'),
                      'no specific properties')
     self.assertEqual(properties123.Get('nothing', 'project'), None)
예제 #5
0
 def Run(self, args):
   configs = named_configs.ConfigurationStore.AllConfigs()
   for _, config in sorted(configs.iteritems()):
     props = properties.VALUES.AllValues(
         list_unset=True,
         properties_file=properties_file.PropertiesFile([config.file_path]),
         only_file_contents=True)
     yield {
         'name': config.name,
         'is_active': config.is_active,
         'properties': props,
     }
예제 #6
0
    def GetProperties(self):
        """Gets the properties defined in this configuration.

    These are the properties literally defined in this file, not the effective
    properties based on other configs or the environment.

    Returns:
      {str, str}, A dictionary of all properties defined in this configuration
      file.
    """
        if not self.file_path:
            return {}
        return properties_file.PropertiesFile([self.file_path]).AllProperties()
예제 #7
0
  def Run(self, args):
    all_configs = named_configs.ConfigurationStore.AllConfigs(
        include_none_config=True)
    config = all_configs.get(args.configuration_name, None)
    if not config:
      raise named_configs.NamedConfigError(
          'The configuration [{0}] does not exist.'
          .format(args.configuration_name))

    return {
        'name': config.name,
        'is_active': config.is_active,
        'properties': properties.VALUES.AllValues(
            list_unset=args.all,
            properties_file=properties_file.PropertiesFile([config.file_path]),
            only_file_contents=True),
    }
예제 #8
0
  def Load():
    """Loads the set of active properties from file.

    This includes both the installation configuration as well as the currently
    active configuration file.

    Returns:
      properties_file.PropertiesFile, The CloudSDK properties.
    """
    ActivePropertiesFile._LOCK.acquire()
    try:
      if not ActivePropertiesFile._PROPERTIES:
        ActivePropertiesFile._PROPERTIES = properties_file.PropertiesFile(
            [config.Paths().installation_properties_path, _ActiveConfig(
                force_create=False).file_path])
    finally:
      ActivePropertiesFile._LOCK.release()
    return ActivePropertiesFile._PROPERTIES
 def testMissing(self):
     properties1 = properties_file.PropertiesFile([self.properties1_file])
     self.assertEqual(properties1.Get('nothing', 'nowhere'), None)
 def testBasicParseFailure(self):
     with self.assertRaises(properties_file.PropertiesParseError):
         properties_file.PropertiesFile([self.bad_properties1_file])
 def testDefaultWhenNotSet(self):
     properties1 = properties_file.PropertiesFile([self.properties1_file])
     self.assertEqual(properties1.Get('core', 'notjohn'), None)
 def testBasicParse(self):
     properties1 = properties_file.PropertiesFile([self.properties1_file])
     self.assertEqual(properties1.Get('core', 'john'), 'cool')