Exemplo n.º 1
0
    def _find_ios_scheme(self, project_dir):
        out = self._output_for("cd \"%s\" && xcodebuild -list" % project_dir)

        match = re.search('Schemes:(.*)', out, re.DOTALL)
        if match is None:
            raise cocos2d.CCPluginError("Couldn't find the schemes list")

        schemes = match.group(1).split()
        if len(schemes) == 0:
            raise cocos2d.CCPluginError("Couldn't find a scheme")

        return schemes[0]
Exemplo n.º 2
0
 def get_relative_path(self, jsfile):
     try:
         # print "current src dir: "+self._current_src_dir)
         pos = jsfile.index(self._current_src_dir)
         if pos != 0:
             raise cocos2d.CCPluginError(
                 "cannot find src directory in file path.")
         # print "origin js path: "+ jsfile
         # print "relative path: "+jsfile[len(self._current_src_dir)+1:]
         return jsfile[len(self._current_src_dir) + 1:]
     except ValueError:
         raise cocos2d.CCPluginError(
             "cannot find src directory in file path.")
Exemplo n.º 3
0
    def _show_versions(self):
        path = os.path.join(self._src_dir, "cocos2dx", "cocos2d.cpp")
        if not os.path.exists(path):
            path = os.path.join(self._src_dir, "cocos", "2d", "cocos2d.cpp")
            if not os.path.exists(path):
                raise cocos2d.CCPluginError("Couldn't find file with version information")

    	with open(path, 'r')  as f:
    		data = f.read()
    		match = re.search('cocos2dVersion\(\)\s*{\s*return\s+"([^"]+)"\s*;', data)
    		if match:
    			print 'cocos2d %s' % match.group(1)
    		else:
    			raise cocos2d.CCPluginError("Couldn't find version info")
Exemplo n.º 4
0
 def _rmdir(self, path):
     if os.path.exists(path):
         try:
             shutil.rmtree(path)
         except OSError as e:
             raise cocos2d.CCPluginError("Error removing directory: " +
                                         str(e.args))
Exemplo n.º 5
0
    def init(self, options, working_dir):
        super(CCPluginDist, self).init(options, working_dir)

        if self._platforms.is_ios_active():
            if not options.provisioning:
                raise cocos2d.CCPluginError("Provisioning profile is needed")
            else:
                self._provisioning = options.provisioning
Exemplo n.º 6
0
    def _get_latest_version(self):
        cocos2d.Logging.info("obtaining latest version number")

        conn = httplib.HTTPConnection('cocos2d-x.org', timeout=10)
        try:
            conn.request('GET', '/download')
            res = conn.getresponse()
            if res.status != httplib.OK:
                raise cocos2d.CCPluginError("Unexpected response status (%d)" % res.status)
            data = res.read()

            #FIXME: quick and dirty (and error prone) way to extract the latest version
            #from the html page
            match = re.search('href="http://cdn.cocos2d-x.org/cocos2d-x-(.*?).zip"', data)
            if match is None:
                raise cocos2d.CCPluginError("Couldn't extract latest version from site")
            
            return match.group(1)
        finally:
            conn.close()
Exemplo n.º 7
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 cocos2d.CCPluginError("Error: cannot create folder in " +
                                            dst_rootpath)

        # print "return jsc path: "+jsc_filepath
        return jsc_filepath
Exemplo n.º 8
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 cocos2d.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._js_files[self._current_src_dir] = []
            self.deep_iterate_dir(src_dir)

        self.reorder_js_files()
        self.handle_all_js_files()
        cocos2d.Logging.info("compilation finished")
Exemplo n.º 9
0
    def dist_amazon(self):
        if not self._platforms.is_amazon_active():
            return
        project_dir = self._platforms.project_path()

        raise cocos2d.CCPluginError("unimplemented")
Exemplo n.º 10
0
    def parse_args(self, argv):
        """
        """
        from optparse import OptionParser

        parser = OptionParser(
            "usage: %prog jscompile -s src_dir -d dst_dir [-c] [-o COMPRESSED_FILENAME] [-j COMPILER_CONFIG] [-m closure_extra_parameters] -v"
        )
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          dest="verbose",
                          help="verbose output")
        parser.add_option(
            "-s",
            "--src",
            action="append",
            type="string",
            dest="src_dir_arr",
            help=
            "source directory of js files needed to be compiled, supports mutiple source directory"
        )

        parser.add_option(
            "-d",
            "--dst",
            action="store",
            type="string",
            dest="dst_dir",
            help="destination directory of js bytecode files to be stored")

        parser.add_option(
            "-c",
            "--use_closure_compiler",
            action="store_true",
            dest="use_closure_compiler",
            default=False,
            help=
            "Whether to use closure compiler to compress all js files into just a big file"
        )

        parser.add_option("-o",
                          "--output_compressed_filename",
                          action="store",
                          dest="compressed_filename",
                          default="game.min.js",
                          help="Only available when '-c' option is used")

        parser.add_option(
            "-j",
            "--compiler_config",
            action="store",
            dest="compiler_config",
            help=
            "The configuration for closure compiler by using JSON, please refer to compiler_config_sample.json"
        )
        parser.add_option(
            "-m",
            "--closure_params",
            action="store",
            dest="closure_params",
            help=
            "Extra parameters to pass to Google Closure Compiler. Values supplied here override the ones defined in the compiler config."
        )

        (options, args) = parser.parse_args(argv)

        if options.src_dir_arr == None:
            raise cocos2d.CCPluginError(
                "Please set source folder by \"-s\" or \"-src\", run ./jscompile.py -h for the usage "
            )
        elif options.dst_dir == None:
            raise cocos2d.CCPluginError(
                "Please set destination folder by \"-d\" or \"-dst\", run ./jscompile.py -h for the usage "
            )
        else:
            for src_dir in options.src_dir_arr:
                if os.path.exists(src_dir) == False:
                    raise cocos2d.CCPluginError(
                        "Error: dir (%s) doesn't exist..." % (src_dir))

        # script directory
        workingdir = os.path.dirname(inspect.getfile(inspect.currentframe()))

        self.init(options, workingdir)