Esempio n. 1
0
def processModule(module_name):
    r"""Builds a command tree out of the configured members of a module.
  """
    Module = sys.modules[module_name]
    MembersTarget = []
    ClassQ = []
    Cls = None
    ClsGroup = None
    ClsGrpMembers = []

    for Member in ModuleMembers[module_name]:
        Underlying = Member.Underlying
        member_name = Member.Config['name']
        member_alias = Member.Config.get('alias', None)

        if ClassQ:
            ClsGroup = ClassQ[-1]
            Cls = ClsGroup.Underlying

            if getattr(
                    Cls, Underlying.__name__, None
            ) is Underlying:  # we got a member tht is a child of the previous class
                if isclass(Underlying):
                    ClassQ.append(Underlying.__ec_member__)

                elif not isunderlying(Underlying):
                    continue

                if member_alias:
                    ClsGrpMembers.insert(0, (member_alias, Member))

                ClsGrpMembers.insert(0, (member_name, Member))
                continue

            elif Cls:  # we've finished adding children to the previous class
                ClsGroup.Members = OrderedDict(ClsGrpMembers)
                ClsGrpMembers = []
                ClassQ.pop()
                Cls = None
                ClsGroup = None

        if isunderlying(Underlying):
            if member_alias:
                MembersTarget.insert(0, (member_alias, Member))

            MembersTarget.insert(0, (member_name, Member))

            if isclass(Underlying):
                ClassQ.append(Underlying.__ec_member__)

    if ClsGroup:
        ClsGroup.Members = OrderedDict(ClsGrpMembers)

    ModuleMembers[module_name] = [
    ]  # remove the existing members from the cache so that they won't be processed again

    if not hasattr(Module.__ec_member__, 'Members'):
        Module.__ec_member__.Members = OrderedDict(MembersTarget)
Esempio n. 2
0
File: core.py Progetto: Laufire/ec
def processModule(module_name):
  r"""Builds a command tree out of the configured members of a module.
  """
  Module = sys.modules[module_name]
  MembersTarget = []
  ClassQ = []
  Cls = None
  ClsGroup = None
  ClsGrpMembers = []

  for Member in ModuleMembers[module_name]:
    Underlying = Member.Underlying
    member_name = Member.Config['name']
    member_alias = Member.Config.get('alias', None)

    if ClassQ:
      ClsGroup = ClassQ[-1]
      Cls = ClsGroup.Underlying

      if getattr(Cls, Underlying.__name__, None) is Underlying: # we got a member tht is a child of the previous class
        if isclass(Underlying):
          ClassQ.append(Underlying.__ec_member__)

        elif not isunderlying(Underlying):
          continue

        if member_alias:
          ClsGrpMembers.insert(0, (member_alias, Member))

        ClsGrpMembers.insert(0, (member_name, Member))
        continue

      elif Cls: # we've finished adding children to the previous class
        ClsGroup.Members = OrderedDict(ClsGrpMembers)
        ClsGrpMembers = []
        ClassQ.pop()
        Cls = None
        ClsGroup = None

    if isunderlying(Underlying):
      if member_alias:
        MembersTarget.insert(0, (member_alias, Member))

      MembersTarget.insert(0, (member_name, Member))

      if isclass(Underlying):
        ClassQ.append(Underlying.__ec_member__)

  if ClsGroup:
    ClsGroup.Members = OrderedDict(ClsGrpMembers)

  ModuleMembers[module_name] = []  # remove the existing members from the cache so that they won't be processed again

  if not hasattr(Module.__ec_member__, 'Members'):
    Module.__ec_member__.Members = OrderedDict(MembersTarget)
Esempio n. 3
0
File: config.py Progetto: Laufire/ec
def group(__decorated__, **Config):
  r"""A decorator to make groups out of classes.

  Config:
    * name (str): The name of the group. Defaults to __decorated__.__name__.
    * desc (str): The description of the group (optional).
    * alias (str): The alias for the group (optional).
  """
  _Group = Group(__decorated__, Config)

  if isclass(__decorated__): # convert the method of the class to static methods so that they could be accessed like object methods; ir: g1/t1(...).
    static(__decorated__)

  state.ActiveModuleMemberQ.insert(0, _Group)

  return _Group.Underlying
Esempio n. 4
0
def group(__decorated__, **Config):
    r"""A decorator to make groups out of classes.

  Config:
    * name (str): The name of the group. Defaults to __decorated__.__name__.
    * desc (str): The description of the group (optional).
    * alias (str): The alias for the group (optional).
  """
    _Group = Group(__decorated__, Config)

    if isclass(
            __decorated__
    ):  # conver the method of the class to static methods so that they could be accessed like object methods; ir: g1/t1(...).
        static(__decorated__)

    state.ActiveModuleMemberQ.insert(0, _Group)

    return _Group.Underlying