Example #1
0
class Project(object):
	_singleton=None
	@staticmethod
	def get():		
		return Project._singleton

	@staticmethod
	def findProject( path = None ):
		#TODO: return project info dict instead of path?
		path = os.path.abspath( path or '' )
		opath = None
		while path and not ( path in ( '', '/','\\' ) ):
			if   os.path.exists( path + '/' + _GII_ENV_CONFIG_DIR ) \
			and  os.path.exists( path + '/' + _GII_INFO_FILE ) :
				#get info
				info = jsonHelper.tryLoadJSON( path + '/' + _GII_INFO_FILE )
				info['path'] = path
				return info
			#go up level
			opath = path
			path = os.path.dirname( path )
			if path == opath: break
		return None

	def __init__(self):
		assert not Project._singleton
		Project._singleton = self

		self.path      = None
		self.cacheManager = CacheManager() 
		self.assetLibrary = AssetLibrary()

		self.info = {
			'name'    : 'Name',
			'author'  : 'author',
			'version' : '1.0.0'
		}

		self.config = {}

	def isLoaded( self ):
		return self.path != None

	def _initPath( self, path ):
		self.path = path

		self.binaryPath        = path + '/' + _GII_BINARY_DIR
		self.gamePath          = path + '/' + _GII_GAME_DIR

		self.envPath           = path + '/' + _GII_ENV_DIR
		self.envPackagePath    = path + '/' + _GII_ENV_PACKAGE_DIR
		self.envDataPath       = path + '/' + _GII_ENV_DATA_DIR
		self.envConfigPath     = path + '/' + _GII_ENV_CONFIG_DIR
		self.envLibPath        = path + '/' + _GII_ENV_LIB_DIR

		self.assetPath         = path + '/' + _GII_ASSET_DIR

		self.scriptLibPath     = path + '/' + _GII_SCRIPT_LIB_DIR

		self.hostPath          = path + '/' + _GII_HOST_DIR
		self.hostExtensionPath = path + '/' + _GII_HOST_EXTENSION_DIR

	def _affirmDirectories( self ):
		#mkdir - lv1
		_affirmPath( self.binaryPath )

		_affirmPath( self.envPath )
		_affirmPath( self.envPackagePath )
		_affirmPath( self.envDataPath )
		_affirmPath( self.envLibPath )
		_affirmPath( self.envConfigPath )

		_affirmPath( self.gamePath )
		_affirmPath( self.assetPath )
		_affirmPath( self.scriptLibPath )
		
		_affirmPath( self.hostPath )
		_affirmPath( self.hostExtensionPath )
		
	def init( self, path, name ):
		info = Project.findProject( path )
		if info:
			raise ProjectException( 'Gii project already initialized:' + info['path'] )
		#
		path = os.path.realpath(path)
		if not os.path.isdir(path):
			raise ProjectException('%s is not a valid path' % path)
		self._initPath( path )
		#
		logging.info( 'copy template contents' )
		from MainModulePath import getMainModulePath
		def ignore( src, names ):
			return ['.DS_Store']
		shutil.copytree( getMainModulePath('template/host'), self.getPath('host'), ignore )
		shutil.copytree( getMainModulePath('template/game'), self.getPath('game'), ignore )
		shutil.copy( getMainModulePath('template/.gitignore'), self.getPath() )
		#
		self._affirmDirectories()

		try:
			self.cacheManager.init( _GII_ENV_CONFIG_DIR, self.envConfigPath )
		except OSError,e:
			raise ProjectException('error creating cache folder:%s' % e)

		self.assetLibrary.load( _GII_ASSET_DIR, self.assetPath, self.path, self.envConfigPath )

		signals.emitNow('project.init', self)
		logging.info( 'project initialized: %s' % path )
		self.info['name'] = name
		self.saveConfig()
		self.save()
		return True	
Example #2
0
class Project(object):
    _singleton = None

    @staticmethod
    def get():
        return Project._singleton

    @staticmethod
    def findProject(path=None):
        #TODO: return project info dict instead of path?
        path = os.path.abspath(path or '')
        opath = None
        while path and not (path in ('', '/', '\\')):
            if   os.path.exists( path + '/' + _GII_ENV_CONFIG_DIR ) \
            and  os.path.exists( path + '/' + _GII_INFO_FILE ) :
                #get info
                info = jsonHelper.tryLoadJSON(path + '/' + _GII_INFO_FILE)
                info['path'] = path
                return info
            #go up level
            opath = path
            path = os.path.dirname(path)
            if path == opath: break
        return None

    def __init__(self):
        assert not Project._singleton
        Project._singleton = self

        self.path = None
        self.cacheManager = CacheManager()
        self.assetLibrary = AssetLibrary()

        self.info = {'name': 'Name', 'author': 'author', 'version': '1.0.0'}

        self.config = {}

    def isLoaded(self):
        return self.path != None

    def _initPath(self, path):
        self.path = path

        self.binaryPath = path + '/' + _GII_BINARY_DIR
        self.gamePath = path + '/' + _GII_GAME_DIR

        self.envPath = path + '/' + _GII_ENV_DIR
        self.envPackagePath = path + '/' + _GII_ENV_PACKAGE_DIR
        self.envDataPath = path + '/' + _GII_ENV_DATA_DIR
        self.envConfigPath = path + '/' + _GII_ENV_CONFIG_DIR
        self.envLibPath = path + '/' + _GII_ENV_LIB_DIR

        self.assetPath = path + '/' + _GII_ASSET_DIR

        self.scriptLibPath = path + '/' + _GII_SCRIPT_LIB_DIR

        self.hostPath = path + '/' + _GII_HOST_DIR
        self.hostExtensionPath = path + '/' + _GII_HOST_EXTENSION_DIR

    def _affirmDirectories(self):
        #mkdir - lv1
        _affirmPath(self.binaryPath)

        _affirmPath(self.envPath)
        _affirmPath(self.envPackagePath)
        _affirmPath(self.envDataPath)
        _affirmPath(self.envLibPath)
        _affirmPath(self.envConfigPath)

        _affirmPath(self.gamePath)
        _affirmPath(self.assetPath)
        _affirmPath(self.scriptLibPath)

        _affirmPath(self.hostPath)
        _affirmPath(self.hostExtensionPath)

    def init(self, path, name):
        info = Project.findProject(path)
        if info:
            raise ProjectException('Gii project already initialized:' +
                                   info['path'])
        #
        path = os.path.realpath(path)
        if not os.path.isdir(path):
            raise ProjectException('%s is not a valid path' % path)
        self._initPath(path)
        #
        logging.info('copy template contents')
        from MainModulePath import getMainModulePath

        def ignore(src, names):
            return ['.DS_Store']

        shutil.copytree(getMainModulePath('template/host'),
                        self.getPath('host'), ignore)
        shutil.copytree(getMainModulePath('template/game'),
                        self.getPath('game'), ignore)
        shutil.copy(getMainModulePath('template/.gitignore'), self.getPath())
        #
        self._affirmDirectories()

        try:
            self.cacheManager.init(_GII_ENV_CONFIG_DIR, self.envConfigPath)
        except OSError, e:
            raise ProjectException('error creating cache folder:%s' % e)

        self.assetLibrary.load(_GII_ASSET_DIR, self.assetPath, self.path,
                               self.envConfigPath)

        signals.emitNow('project.init', self)
        logging.info('project initialized: %s' % path)
        self.info['name'] = name
        self.saveConfig()
        self.save()
        return True