示例#1
0
    def append_h5_engine(self, v):
        src = os.path.join(self.cocos_root, v['from'])
        dst = os.path.join(self.project_dir, v['to'])
        # check cocos engine exist
        moduleConfig = 'moduleConfig.json'
        moudle_cfg = os.path.join(src, moduleConfig)
        if not os.path.exists(moudle_cfg):
            message = "Fatal: %s doesn't exist." % moudle_cfg
            raise cocos.CCPluginError(message)

        f = open(moudle_cfg)
        data = json.load(f, 'utf8')
        f.close()
        modules = data['module']

        # must copy moduleConfig.json & CCBoot.js
        file_list = [moduleConfig, data['bootFile']]
        for k, v in modules.iteritems():
            module = modules[k]
            for f in module:
                if f[-2:] == 'js':
                    file_list.append(f)

        # begin copy engine
        cocos.Logging.info("> Copying cocos2d-html5 files...")
        for index in range(len(file_list)):
            srcfile = os.path.join(src, file_list[index])
            dstfile = os.path.join(dst, file_list[index])

            srcfile = cocos.add_path_prefix(srcfile)
            dstfile = cocos.add_path_prefix(dstfile)

            if not os.path.exists(os.path.dirname(dstfile)):
                os.makedirs(cocos.add_path_prefix(os.path.dirname(dstfile)))

            # copy file or folder
            if os.path.exists(srcfile):
                if os.path.isdir(srcfile):
                    if os.path.exists(dstfile):
                        shutil.rmtree(dstfile)
                    shutil.copytree(srcfile, dstfile)
                else:
                    if os.path.exists(dstfile):
                        os.remove(dstfile)
                    shutil.copy2(srcfile, dstfile)
示例#2
0
def check_jdk_version():
    commands = ["java", "-version"]
    child = subprocess.Popen(commands, stderr=subprocess.PIPE)

    jdk_version = None
    for line in child.stderr:
        if 'java version' in line:
            if '1.7' in line:
                jdk_version = JDK_1_7
            if '1.6' in line:
                jdk_version = JDK_1_6

    child.wait()

    if jdk_version is None:
        raise cocos.CCPluginError("Not valid jdk isntalled")

    return jdk_version
示例#3
0
    def get_api_level(self, target_str, raise_error=True):
        special_targats_info = {"android-4.2": 17, "android-L": 20}

        if special_targats_info.has_key(target_str):
            ret = special_targats_info[target_str]
        else:
            match = re.match(r'android-(\d+)', target_str)
            if match is not None:
                ret = int(match.group(1))
            else:
                if raise_error:
                    raise cocos.CCPluginError(
                        cocos.MultiLanguage.get_string(
                            'COMPILE_ERROR_NOT_VALID_AP_FMT') % target_str)
                else:
                    ret = -1

        return ret
    def run(self):
        package_name = self._package_name
        package_path = self._package_path
        if not os.path.isdir(package_path):
            raise cocos.CCPluginError("ERROR: The path '%s' is not found!" % package_path)

        sln_txt =  self.load_sln_win32()
        if sln_txt is None:
            print "Read error: *.sln file for platform 'win'"
        else:
            find_tag = '(Project\(\"\{)(\S*)(\}\"\) = \"' + package_name + '\", \"\S*\", \"\{)(\S*)(\}\"\s*EndProject)'
            match = re.search(find_tag, sln_txt, re.DOTALL)
            if match is None:
                print "Not found project '%s' in *.sln for platform 'win'" %package_name
            else:
                proj_id_win = match.group(2)
                build_id_win = match.group(4)
                self.set_win32(proj_id_win, build_id_win)
示例#5
0
    def get_api_level(self, target_str, raise_error=True):
        special_targats_info = {"android-4.2": 17, "android-L": 20}

        if special_targats_info.has_key(target_str):
            ret = special_targats_info[target_str]
        else:
            match = re.match(r'android-(\d+)', target_str)
            if match is not None:
                ret = int(match.group(1))
            else:
                if raise_error:
                    raise cocos.CCPluginError(
                        "%s is not a valid android target platform." %
                        target_str)
                else:
                    ret = -1

        return ret
示例#6
0
    def update_project(self, android_platform):
        # Android SDK removed android command & ant support from SDK tools 25.3.0
        # So, we should check the Android SDK tools version
        sdk_tools_folder = os.path.join(self.sdk_root, 'tools')
        main_ver, minor_ver = self._get_android_sdk_tools_ver(sdk_tools_folder)
        no_ant = False
        if main_ver > 25 or (main_ver == 25 and minor_ver >= 3):
            no_ant = True

        if not self.use_studio and no_ant:
            # Tip the message that ant is not supported from Android SDK tools 25.3.0
            raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_ANT_NOT_SUPPORTED'),
                                      cocos.CCPluginError.ERROR_OTHERS)

        if self.use_studio:
            manifest_path = os.path.join(self.app_android_root, 'app')
        else:
            manifest_path = self.app_android_root

        # check the android platform
        target_str = self.check_android_platform(self.sdk_root, android_platform, manifest_path)

        if no_ant:
            # should manually update the project
            self._write_local_properties(manifest_path)
            self._update_project_properties(manifest_path, target_str)
        else:
            # update project
            sdk_tool_path = os.path.join(sdk_tools_folder, "android")
            command = "%s update project -t %s -p %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), target_str, manifest_path)
            self._run_cmd(command)

            # update lib-projects
            self.update_lib_projects(self.sdk_root, sdk_tool_path, android_platform, manifest_path)

        if self.use_studio:
            # copy the local.properties to the app_android_root
            file_name = 'local.properties'
            src_path = os.path.normpath(os.path.join(manifest_path, file_name))
            dst_path = os.path.normpath(os.path.join(self.app_android_root, file_name))
            if src_path != dst_path:
                if os.path.isfile(dst_path):
                    os.remove(dst_path)
                shutil.copy(src_path, dst_path)
示例#7
0
    def _create_from_cmd(self):
        # check the dst project dir exists
        if os.path.exists(self._projdir):
            message = cocos.MultiLanguage.get_string(
                'NEW_ERROR_FOLDER_EXISTED_FMT') % self._projdir
            raise cocos.CCPluginError(message)

        tp_dir = self._templates.template_path()

        creator = TPCreator(self._lang, self._cocosroot, self._projname,
                            self._projdir, self._tpname, tp_dir, self._package,
                            self._mac_bundleid, self._ios_bundleid)
        # do the default creating step
        creator.do_default_step()

        data = None
        cfg_path = os.path.join(self._projdir, cocos_project.Project.CONFIG)
        if os.path.isfile(cfg_path):
            f = open(cfg_path)
            data = json.load(f)
            f.close()

        if data is None:
            data = {}

        if cocos_project.Project.KEY_PROJ_TYPE not in data:
            data[cocos_project.Project.KEY_PROJ_TYPE] = self._lang

        # script project may add native support
        if self._lang in (cocos_project.Project.LUA, cocos_project.Project.JS):
            if not self._other_opts.no_native:
                creator.do_other_step('do_add_native_support')
                data[cocos_project.Project.KEY_HAS_NATIVE] = True
            else:
                data[cocos_project.Project.KEY_HAS_NATIVE] = False

        # if --portrait is specified, change the orientation
        if self._other_opts.portrait:
            creator.do_other_step("change_orientation",
                                  not_existed_error=False)

        # write config files
        with open(cfg_path, 'w') as outfile:
            json.dump(data, outfile, sort_keys=True, indent=4)
    def _gen_available_platforms(self, proj_info):
        # generate the platform list for different projects
        if self._project._is_lua_project():
            if self._project._is_native_support():
                platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.LINUX ]
            else:
                if self._project.has_android_libs():
                    platform_list = [ Platforms.ANDROID ]
                else:
                    platform_list = []
        elif self._project._is_js_project():
            if self._project._is_native_support():
                platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.WEB, Platforms.LINUX]
            else:
                if self._project.has_android_libs():
                    platform_list = [ Platforms.ANDROID, Platforms.WEB ]
                else:
                    platform_list = [ Platforms.WEB ]
        elif self._project._is_cpp_project():
            platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.LINUX ]

        # filter the available platform list
        platform_list = self._filter_platforms(platform_list)

        # check the real available platforms
        self._available_platforms = {}
        root_path = self._project.get_project_dir()
        for p in platform_list:
            cfg_class = cocos.get_class(Platforms.CFG_CLASS_MAP[p])
            if cfg_class is None:
                continue

            cfg_key = "%s_cfg" % p
            if proj_info.has_key(cfg_key):
                cfg_obj = cfg_class(root_path, self._project._is_script_project(), proj_info[cfg_key])
            else:
                cfg_obj = cfg_class(root_path, self._project._is_script_project())

            if cfg_obj._is_available():
                self._available_platforms[p] = cfg_obj

        # don't have available platforms
        if len(self._available_platforms) == 0:
            raise cocos.CCPluginError("There isn't any available platforms")
示例#9
0
def select_toolchain_version(ndk_root):
    '''Because ndk-r8e uses gcc4.6 as default. gcc4.6 doesn't support c++11. So we should select gcc4.7 when
    using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
    Conclution:
    ndk-r8e  -> use gcc4.7
    ndk-r9   -> use gcc4.8
    '''

    if os.path.isdir(
            os.path.join(ndk_root, "toolchains", "arm-linux-androideabi-4.8")):
        os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8'
        cocos.Logging.info("The Selected NDK toolchain version was 4.8 !")
    elif os.path.isdir(
            os.path.join(ndk_root, "toolchains", "arm-linux-androideabi-4.7")):
        os.environ['NDK_TOOLCHAIN_VERSION'] = '4.7'
        cocos.Logging.info("The Selected NDK toolchain version was 4.7 !")
    else:
        message = "Couldn't find the gcc toolchain."
        raise cocos.CCPluginError(message)
示例#10
0
    def _parse_cfg(self):
        self.cfg_path = os.path.join(self.app_android_root, BUILD_CFIG_FILE)
        try:
            f = open(self.cfg_path)
            cfg = json.load(f, encoding='utf8')
            f.close()
        except Exception:
            raise cocos.CCPluginError(
                "Configuration file \"%s\" is not existed or broken!" %
                self.cfg_path)

        if cfg.has_key(
                project_compile.CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES):
            if self._no_res:
                self.res_files = cfg[project_compile.CCPluginCompile.
                                     CFG_KEY_MUST_COPY_RESOURCES]
            else:
                self.res_files = cfg[
                    project_compile.CCPluginCompile.
                    CFG_KEY_MUST_COPY_RESOURCES] + cfg[
                        project_compile.CCPluginCompile.CFG_KEY_COPY_RESOURCES]
        else:
            self.res_files = cfg[
                project_compile.CCPluginCompile.CFG_KEY_COPY_RESOURCES]

        self.ndk_module_paths = cfg['ndk_module_path']

        # get the properties for sign release apk
        self.key_store = None
        if cfg.has_key(AndroidBuilder.CFG_KEY_STORE):
            self.key_store = cfg[AndroidBuilder.CFG_KEY_STORE]

        self.key_store_pass = None
        if cfg.has_key(AndroidBuilder.CFG_KEY_STORE_PASS):
            self.key_store_pass = cfg[AndroidBuilder.CFG_KEY_STORE_PASS]

        self.alias = None
        if cfg.has_key(AndroidBuilder.CFG_KEY_ALIAS):
            self.alias = cfg[AndroidBuilder.CFG_KEY_ALIAS]

        self.alias_pass = None
        if cfg.has_key(AndroidBuilder.CFG_KEY_ALIAS_PASS):
            self.alias_pass = cfg[AndroidBuilder.CFG_KEY_ALIAS_PASS]
示例#11
0
    def query_package_data(cls, name, version='all'):
        url = cls.QUERY_PACKAGE_URL % name + '&version=' + version
        # print "[PACKAGE] query url: %s" % url
        response = urllib2.urlopen(url)
        html = response.read()
        package_data = json.loads(html)
        # d1 = json.dumps(package_data,indent=4)
        # print d1
        if package_data is None or len(package_data) == 0 or (
                "err" in package_data and "code" in package_data
                and package_data["code"] == "1002"):
            return None

        if "err" in package_data:
            message = cocos.MultiLanguage.get_string('PACKAGE_ERROR_WITH_CODE_FMT')\
                      % (package_data["err"], package_data["code"])
            raise cocos.CCPluginError(message)

        return package_data
示例#12
0
    def append_x_engine(self, v):
        src = os.path.join(self.cocos_root, v['from'])
        dst = os.path.join(self.project_dir, v['to'])

        # check cocos engine exist
        cocosx_files_json = os.path.join(src, 'templates',
                                         'cocos2dx_files.json')
        if not os.path.exists(cocosx_files_json):
            message = "Fatal: %s doesn\'t exist." % cocosx_files_json
            raise cocos.CCPluginError(message)

        f = open(cocosx_files_json)
        data = json.load(f)
        f.close()

        fileList = data['common']
        if self.lang == 'lua':
            fileList = fileList + data['lua']

        #begin copy engine
        cocos.Logging.info("> Copying cocos2d-x files...")

        for index in range(len(fileList)):
            srcfile = os.path.join(src, fileList[index])
            dstfile = os.path.join(dst, fileList[index])

            srcfile = cocos.add_path_prefix(srcfile)
            dstfile = cocos.add_path_prefix(dstfile)

            if not os.path.exists(os.path.dirname(dstfile)):
                os.makedirs(cocos.add_path_prefix(os.path.dirname(dstfile)))

            #copy file or folder
            if os.path.exists(srcfile):
                if os.path.isdir(srcfile):
                    if os.path.exists(dstfile):
                        shutil.rmtree(dstfile)
                    shutil.copytree(srcfile, dstfile)
                else:
                    if os.path.exists(dstfile):
                        os.remove(dstfile)
                    shutil.copy2(srcfile, dstfile)
示例#13
0
def check_jdk_version():
    commands = ["java", "-version"]
    child = subprocess.Popen(commands, stderr=subprocess.PIPE)

    jdk_version = None
    for line in child.stderr:
        if 'java version' in line:
            if '1.6' in line:
                jdk_version = JDK_1_6
            else:
                jdk_version = JDK_1_7

    child.wait()

    if jdk_version is None:
        raise cocos.CCPluginError(
            MultiLanguage.get_string('COMPILE_ERROR_NO_VALID_JDK'),
            cocos.CCPluginError.ERROR_TOOLS_NOT_FOUND)

    return jdk_version
示例#14
0
 def project_replace_package_name(self, v):
     """ will modify the content of the file
     """
     dst_project_dir = self.project_dir
     dst_project_name = self.project_name
     src_package_name = v['src_package_name']
     dst_package_name = self.package_name
     cocos.Logging.info("> Replace the project package name from '%s' to '%s'" % (
         src_package_name, dst_package_name))
     files = v['files']
     if not dst_package_name:
         raise cocos.CCPluginError('package name not specified')
     for f in files:
         dst = f.replace("PROJECT_NAME", dst_project_name)
         if os.path.exists(os.path.join(dst_project_dir, dst)):
             replace_string(
                 os.path.join(dst_project_dir, dst), src_package_name, dst_package_name)
         else:
             cocos.Logging.warning(
                 "%s not found" % os.path.join(dst_project_dir, dst))
    def get_output_file_path(self, jsfile):
        """
        Gets output file path by source js file
        """
        # create folder for generated file
        jsc_filepath = ""
        relative_path = self.get_relative_path(jsfile)+"c"
        jsc_filepath = os.path.join(self._dst_dir, relative_path)

        dst_rootpath = os.path.split(jsc_filepath)[0]
        try:
            # print "creating dir (%s)" % (dst_rootpath)
            os.makedirs(dst_rootpath)
        except OSError:
            if os.path.exists(dst_rootpath) == False:
                # There was an error on creation, so make sure we know about it
                raise cocos.CCPluginError("Error: cannot create folder in "+dst_rootpath)

        # print "return jsc path: "+jsc_filepath
        return jsc_filepath
示例#16
0
    def init(self, options, workingdir):
        """
        Arguments:
        - `options`:
        """
        self._current_src_dir = None
        self._src_dir_arr = self.normalize_path_in_list(options.src_dir_arr)
        self._dst_dir = options.dst_dir
        self._verbose = options.verbose
        self._workingdir = workingdir
        self._lua_files = {}
        self._isEncrypt = options.encrypt
        self._encryptkey = options.encryptkey
        self._encryptsign = options.encryptsign
        self._luajit_exe_path = self.get_luajit_path()

        if self._luajit_exe_path is None:
            raise cocos.CCPluginError("Can't find right luajit for current system.")

        self._luajit_dir = os.path.dirname(self._luajit_exe_path)
示例#17
0
    def _run_ios_app(self, ios_app_path):
        if not cocos.os_is_mac():
            raise cocos.CCPluginError('Now only support run iOS simulator on Mac OS')

        # get bundle id
        bundle_id = self._get_bundle_id(ios_app_path)

        # find simulator
        simulator_id = self._get_simulator_id()

        try:
            # run the simulator
            self._run_cmd('xcrun instruments -w "%s"' % simulator_id)
        except Exception as e:
            pass

        # install app
        self._run_cmd('xcrun simctl install "%s" "%s"' % (simulator_id, ios_app_path))

        # run app
        self._run_cmd('xcrun simctl launch "%s" "%s"' % (simulator_id, bundle_id))
示例#18
0
    def _scan(self):
        templates_dir = self._templates_dir
        dirs =  [ name for name in os.listdir(templates_dir) if os.path.isdir(os.path.join(templates_dir, name)) ]
        template_pattern = {
                "cpp" : 'cpp-template-(.+)',
                "lua" : 'lua-template-(.+)',
                "js" : 'js-template-(.+)',
                }
        pattern = template_pattern[self._lang]
        valid_dirs = [ name for name in dirs if re.search(pattern, name) is not None]

        # store the template dir full path, eg. { 'name' : 'full_path'}
        folders = {re.search(pattern, path).group(1) : os.path.join(templates_dir, path) for path in valid_dirs}
        self._template_folders = folders

        if len(folders) == 0:
            cur_engine = "cocos2d-x" if self._lang == "js" else "cocos2d-js"
            need_engine = "cocos2d-js" if self._lang == "js" else "cocos2d-x"
            engine_tip = "You can't create a %s game in %s. Please use %s instead." % (self._lang, cur_engine, need_engine)
            message = "Fatal: can't find any template for <%s> language in %s\n%s" % (self._lang, templates_dir, engine_tip)
            raise cocos.CCPluginError(message)
示例#19
0
    def run(self):
        package_name = self._package_name
        package_path = self._package_path
        if not os.path.isdir(package_path):
            raise cocos.CCPluginError(
                cocos.MultiLanguage.get_string(
                    'PACKAGE_ERROR_PATH_NOT_FOUND_FMT') % package_path)

        sln_txt = self.load_sln_win32()
        if sln_txt is None:
            print cocos.MultiLanguage.get_string('PACKAGE_ERROR_READ_SLN')
        else:
            find_tag = '(Project\(\"\{)(\S*)(\}\"\) = \"' + package_name + '\", \"\S*\", \"\{)(\S*)(\}\"\s*EndProject)'
            match = re.search(find_tag, sln_txt, re.DOTALL)
            if match is None:
                print cocos.MultiLanguage.get_string(
                    'PACKAGE_ERROR_NOT_FOUND_PROJ') % package_name
            else:
                proj_id_win = match.group(2)
                build_id_win = match.group(4)
                self.set_win32(proj_id_win, build_id_win)
示例#20
0
    def run(self, argv, dependencies):
        """
        """
        self.parse_args(argv)

        # create output directory
        try:
            os.makedirs(self._dst_dir)
        except OSError:
            if os.path.exists(self._dst_dir) == False:
                raise cocos.CCPluginError("Error: cannot create folder in " + self._dst_dir)

        # deep iterate the src directory
        for src_dir in self._src_dir_arr:
            self._current_src_dir = src_dir
            self._lua_files[self._current_src_dir] = []
            self.deep_iterate_dir(src_dir)

        self.handle_all_lua_files()

        cocos.Logging.info("compilation finished")
示例#21
0
    def _scan(self):
        template_pattern = {
            "cpp": 'cpp-template-(.+)',
            "lua": 'lua-template-(.+)',
            "js": 'js-template-(.+)',
        }

        self._template_folders = {}

        for templates_dir in self._templates_paths:
            try:
                dirs = [
                    name for name in os.listdir(templates_dir)
                    if os.path.isdir(os.path.join(templates_dir, name))
                ]
            except Exception:
                continue

            pattern = template_pattern[self._lang]
            for name in dirs:
                match = re.search(pattern, name)
                if match is None:
                    continue

                template_name = match.group(1)
                if template_name in self._template_folders.keys():
                    continue

                self._template_folders[template_name] = os.path.join(
                    templates_dir, name)

        if len(self._template_folders) == 0:
            cur_engine = "cocos2d-x" if self._lang == "js" else "cocos2d-js"
            need_engine = "cocos2d-js" if self._lang == "js" else "cocos2d-x"
            engine_tip = MultiLanguage.get_string('NEW_ERROR_ENGINE_TIP_FMT',
                                                  need_engine)
            message = MultiLanguage.get_string(
                'NEW_ERROR_TEMPLATE_NOT_FOUND_FMT', (self._lang, engine_tip))
            raise cocos.CCPluginError(message,
                                      cocos.CCPluginError.ERROR_PATH_NOT_FOUND)
示例#22
0
    def do_add_header_lib_on_win(self, source, tag):
        workdir, proj_file_path, lines = self.load_proj_win32()
        contents = []
        tag_found = False
        for line in lines:
            match = re.search(tag, line)
            if match is None:
                contents.append(line)
            else:
                includes = re.split(';', match.group(2))
                headers = []
                for include in includes:
                    include = self.get_win32_path(workdir, include)
                    if include is not None:
                        headers.append(include)

                headers.append(self.get_win32_path(workdir, source))
                headers = list(set(headers))
                start, end = match.span(0)
                parts = []
                parts.append(line[:start])
                parts.append(match.group(1))
                parts.append(';')
                for header in headers:
                    if header.find(' ') != -1:
                        header = '"' + header + '"'
                    parts.append(header)
                    parts.append(';')
                parts.append(match.group(3))
                parts.append(line[end:])
                contents.append(''.join(parts))
                tag_found = True

        if tag_found == False:
            raise cocos.CCPluginError(
                "Not found header TAG in project for platform 'win32'")
        else:
            f = open(proj_file_path, "wb")
            f.writelines(contents)
            f.close()
示例#23
0
    def get_output_file_path(self, luafile):
        """
        Gets output file path by source lua file
        """
        # create folder for generated file
        luac_filepath = ""
        # Unknow to remove 'c'
        relative_path = self.get_relative_path(luafile)+"c"
        luac_filepath = os.path.join(self._dst_dir, relative_path)

        dst_rootpath = os.path.split(luac_filepath)[0]
        try:
            # print "creating dir (%s)" % (dst_rootpath)
            os.makedirs(dst_rootpath)
        except OSError:
            if os.path.exists(dst_rootpath) == False:
                # There was an error on creation, so make sure we know about it
                raise cocos.CCPluginError(cocos.MultiLanguage.get_string('LUACOMPILE_ERROR_MKDIR_FAILED_FMT')
                                          % dst_rootpath)

        # print "return luac path: "+luac_filepath
        return luac_filepath
示例#24
0
    def deploy_wp8(self, dependencies):
        if not self._platforms.is_wp8_active():
            return

        compile_dep = dependencies['compile']
        run_root = compile_dep.run_root
        product_id = compile_dep.product_id
        xap_file_name = compile_dep.xap_file_name
        self.xap_path = os.path.join(run_root, xap_file_name)

        # find the XapDeployCmd.exe
        self.deploy_tool = self.find_xap_deploy_tool()
        if self.deploy_tool is None:
            raise cocos.CCPluginError(MultiLanguage.get_string('DEPLOY_ERROR_XAPCMD_NOT_FOUND'),
                                      cocos.CCPluginError.ERROR_TOOLS_NOT_FOUND)

        # uninstall the app on wp8 by product ID
        try:
            uninstall_cmd = '"%s" /uninstall %s /targetdevice:xd' % (self.deploy_tool, product_id)
            self._run_cmd(uninstall_cmd)
        except:
            pass
示例#25
0
    def project_replace_so_name(self, v):
        """ will modify the content of the file
        """
        src_so_name = v['src_so_name']
        dst_so_name = self.project_name
        if src_so_name == dst_so_name:
            return

        cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_REPLACE_SO_FMT',
                                                    (src_so_name, dst_so_name)))
        files = v['files']
        if not dst_so_name:
            raise cocos.CCPluginError(MultiLanguage.get_string('NEW_ERROR_PKG_NAME_NOT_SPECIFIED'),
                                      cocos.CCPluginError.ERROR_WRONG_ARGS)
        for f in files:
            dst = f.replace("PROJECT_NAME", self.project_name)
            dstpath = os.path.join(self.project_dir, dst)
            if os.path.exists(dstpath):
                replace_string(dstpath, src_so_name, dst_so_name)
            else:
                cocos.Logging.warning(MultiLanguage.get_string('NEW_WARNING_FILE_NOT_FOUND_FMT',
                                                               dstpath))
示例#26
0
    def _scan(self):
        template_pattern = {
            "cpp": 'cpp-template-(.+)',
            "lua": 'lua-template-(.+)',
            "js": 'js-template-(.+)',
        }

        self._template_folders = {}

        for templates_dir in self._templates_paths:
            try:
                dirs = [
                    name for name in os.listdir(templates_dir)
                    if os.path.isdir(os.path.join(templates_dir, name))
                ]
            except Exception:
                continue

            pattern = template_pattern[self._lang]
            for name in dirs:
                match = re.search(pattern, name)
                if match is None:
                    continue

                template_name = match.group(1)
                if template_name in self._template_folders.keys():
                    continue

                self._template_folders[template_name] = os.path.join(
                    templates_dir, name)

        if len(self._template_folders) == 0:
            cur_engine = "cocos2d-x" if self._lang == "js" else "cocos2d-js"
            need_engine = "cocos2d-js" if self._lang == "js" else "cocos2d-x"
            engine_tip = "You can specify the path of %s by argument '-e'." % need_engine
            message = "Fatal: can't find any template for <%s> language in %s\n%s" % (
                self._lang, templates_dir, engine_tip)
            raise cocos.CCPluginError(message)
示例#27
0
    def _create_from_cmd(self):
        #check the dst project dir exists
        if os.path.exists(self._projdir):
            message = "Fatal: %s folder is already exist" % self._projdir
            raise cocos.CCPluginError(message)

        tp_dir = self._templates.template_path()

        creator = TPCreator(self._lang, self._cocosroot, self._projname,
                            self._projdir, self._tpname, tp_dir, self._package,
                            self._mac_bundleid, self._ios_bundleid)
        # do the default creating step
        creator.do_default_step()

        data = None
        cfg_path = os.path.join(self._projdir, cocos_project.Project.CONFIG)
        if os.path.isfile(cfg_path):
            f = open(cfg_path)
            data = json.load(f)
            f.close()

        if data is None:
            data = {}

        if not data.has_key(cocos_project.Project.KEY_PROJ_TYPE):
            data[cocos_project.Project.KEY_PROJ_TYPE] = self._lang

        # script project may add native support
        if self._lang in (cocos_project.Project.LUA, cocos_project.Project.JS):
            if not self._other_opts.no_native:
                creator.do_other_step('do_add_native_support')
                data[cocos_project.Project.KEY_HAS_NATIVE] = True
            else:
                data[cocos_project.Project.KEY_HAS_NATIVE] = False

        # write config files
        with open(cfg_path, 'w') as outfile:
            json.dump(data, outfile, sort_keys=True, indent=4)
示例#28
0
    def get_output_file_path(self, jsfile):
        """
        Gets output file path by source js file
        """
        # create folder for generated file
        jsc_filepath = ""
        relative_path = self.get_relative_path(jsfile) + "c"
        jsc_filepath = os.path.join(self._dst_dir, relative_path)

        dst_rootpath = os.path.split(jsc_filepath)[0]
        try:
            # print "creating dir (%s)" % (dst_rootpath)
            os.makedirs(dst_rootpath)
        except OSError:
            if os.path.exists(dst_rootpath) == False:
                # There was an error on creation, so make sure we know about it
                raise cocos.CCPluginError(
                    MultiLanguage.get_string(
                        'LUACOMPILE_ERROR_MKDIR_FAILED_FMT', dst_rootpath),
                    cocos.CCPluginError.ERROR_PATH_NOT_FOUND)

        # print "return jsc path: "+jsc_filepath
        return jsc_filepath
示例#29
0
    def init(self, options, workingdir):
        """
        Arguments:
        - `options`:
        """
        self._current_src_dir = None
        self._src_dir_arr = self.normalize_path_in_list(options.src_dir_arr)
        self._dst_dir = options.dst_dir
        if not os.path.isabs(self._dst_dir):
            self._dst_dir = os.path.abspath(self._dst_dir)
        self._verbose = options.verbose
        self._workingdir = workingdir
        self._lua_files = {}
        self._isEncrypt = options.encrypt
        self._encryptkey = options.encryptkey
        self._encryptsign = options.encryptsign
        self._luajit_exe_path = self.get_luajit_path()
        self._disable_compile = options.disable_compile

        if self._luajit_exe_path is None:
            raise cocos.CCPluginError(cocos.MultiLanguage.get_string('LUACOMPILE_ERROR_TOOL_NOT_FOUND'))

        self._luajit_dir = os.path.dirname(self._luajit_exe_path)
示例#30
0
    def deploy_wp8(self, dependencies):
        if not self._platforms.is_wp8_active():
            return

        compile_dep = dependencies['compile']
        run_root = compile_dep.run_root
        product_id = compile_dep.product_id
        xap_file_name = compile_dep.xap_file_name
        self.xap_path = os.path.join(run_root, xap_file_name)

        # find the XapDeployCmd.exe
        self.deploy_tool = self.find_xap_deploy_tool()
        if self.deploy_tool is None:
            raise cocos.CCPluginError(
                "XapDeployCmd.exe not found, can't deploy the application.")

        # uninstall the app on wp8 by product ID
        try:
            uninstall_cmd = '"%s" /uninstall %s /targetdevice:xd' % (
                self.deploy_tool, product_id)
            self._run_cmd(uninstall_cmd)
        except:
            pass