1. Alex Chi
  2. nacl automake

Commits

Alex Chi  committed 1c2bab9

[TASK] ready for more functions

  • Participants
  • Parent commits 17929c5
  • Branches master

Comments (0)

Files changed (3)

File naclautomake/common.py

View file
+'''
+Created on 2013-2-7
+
+@author: Alex Chi
+'''
+
+def Enum(**enums):
+    '''
+From: StackOverflow
+Url: http://stackoverflow.com/questions/36932/whats-the-best-way-to-implement-an-enum-in-python
+    '''
+    return type('Enum', (), enums)
+
+EProjectType = Enum(SLIB = 'a', DLIB = 'so', NEXE = 'nexe')
+EToolChain = Enum(NEWLIB = 'newlib', GLIBC = 'glibc', ARM = 'arm', PNACL = 'pnacl')
+EMakeType = Enum(DEBUG = 'debug', PROFILE = 'profile', DEPLOY = 'deploy')
+
+def UniqueSet(aset):
+    '''
+remove repeated item in set
+    '''
+    return set(aset)
+
+def UniqueList(alist):
+    '''
+remove repeated item in list
+    '''
+    return list(UniqueSet(alist))

File naclautomake/project.py

View file
+'''
+Created on 2013-2-7
+
+@author: Alex Chi
+'''
+from common import EProjectType
+
+class NaClProject(object):
+    '''
+a project that contain all code files
+    '''
+
+    def __init__(self, projecttype = EProjectType.NEXE):
+        self.__type__ = projecttype
+
+    @property
+    def type(self):
+        return self.__type__
+
+    @type.setter
+    def type(self, value):
+        self.__type__ = value
+
+ncp = NaClProject(EProjectType.DLIB)
+print ncp
+print ncp.type
+ncp.type = EProjectType.SLIB
+print ncp.type
+print ncp.__doc__

File naclautomake/solution.py

View file
+'''
+Created on 2013-2-7
+
+@author: Alex Chi
+'''
+from common import EToolChain
+from common import EMakeType
+from common import UniqueSet
+from project import NaClProject
+
+class NaClSolution(object):
+    '''
+a solution that contain all projects
+    '''
+
+    def __init__(self, toolchains = (EToolChain.NEWLIB), maketypes = (EMakeType.DEBUG)):
+        self.__projects__ = []
+        self.__toolchains__ = UniqueSet(toolchains)
+        self.__maketypes__ = UniqueSet(maketypes)
+
+    @property
+    def toolchains(self):
+        return self.__toolchains__
+
+    @toolchains.setter
+    def toolchains(self, value):
+        self.__toolchains__ = UniqueSet(value)
+
+    @property
+    def maketypes(self):
+        return self.__maketypes__
+
+    @maketypes.setter
+    def maketypes(self, value):
+        self.__maketypes__ = UniqueSet(value)
+
+    def newProject(self):
+        tmp = NaClProject()
+        self.__projects__.append(tmp)
+        return tmp