Revision 870dc44c lib/objects.py

b/lib/objects.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2006, 2007 Google Inc.
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
861 861
  @ivar supported_parameters: a list of tuples, name and description,
862 862
      containing the supported parameters by this OS
863 863

  
864
  @type VARIANT_DELIM: string
865
  @cvar VARIANT_DELIM: the variant delimiter
866

  
864 867
  """
865 868
  __slots__ = [
866 869
    "name",
......
875 878
    "supported_parameters",
876 879
    ]
877 880

  
881
  VARIANT_DELIM = "+"
882

  
883
  @classmethod
884
  def SplitNameVariant(cls, name):
885
    """Splits the name into the proper name and variant.
886

  
887
    @param name: the OS (unprocessed) name
888
    @rtype: list
889
    @return: a list of two elements; if the original name didn't
890
        contain a variant, it's returned as an empty string
891

  
892
    """
893
    nv = name.split(cls.VARIANT_DELIM, 1)
894
    if len(nv) == 1:
895
      nv.append("")
896
    return nv
897

  
898
  @classmethod
899
  def GetName(cls, name):
900
    """Returns the proper name of the os (without the variant).
901

  
902
    @param name: the OS (unprocessed) name
903

  
904
    """
905
    return cls.SplitNameVariant(name)[0]
906

  
907
  @classmethod
908
  def GetVariant(cls, name):
909
    """Returns the variant the os (without the base name).
910

  
911
    @param name: the OS (unprocessed) name
912

  
913
    """
914
    return cls.SplitNameVariant(name)[1]
915

  
878 916

  
879 917
class Node(TaggableObject):
880 918
  """Config object representing a node."""

Also available in: Unified diff