Ejemplo n.º 1
0
 def __createProjectConfig( self ):
     message( LOC["CONFIGING_PROJECT"] )
     name     = self["project_name"] + ".sublime-project"
     filename = os.path.join( self["project_directory"], name ).replace( "\\", "/" )
     self.__terr.expanData({
         "title" : LOC["CREATE_PROJECT_FAIL"],
         "error" : LOC["CONFIG_PROJECT_FAIL"],
         "file"  : filename
     })
     self.__terr.setTemple( 
         "${title}\n"
         "${error}\n"
         "${file}"
     )
     d = {
         "project_name" : self["project_name"]
     }
     temp = StringTemple( "", self.__dict )
     content = ""
     with open( self.__projectconfig, "r" ) as fobj:
         content += fobj.read()
     try:
         fobj = open( filename, "w" )
         fobj.write( temp.parse( content ) )
     except Exception, e:
         raise e
Ejemplo n.º 2
0
    def run( self ):
        #将LOC GFG DLOC等这些变量定义到当前模块 
        JProject.moduleInit( __name__ )

        self.__dict         = {
            "project_name"      : "",
            "project_directory" : ""
        }

        self.__project_name = ""
        self.__projectconfig= os.path.join( PPATH, "project.config" )
        default_directory   = os.path.expanduser( "~\\My Documents\\" )
        self.__input        = None
        self.__terr         = StringTemple( "", {} )

        #请求输入队列
        self.__iqueue       = Queue( 0, [
            #( <property>, <status message>, <caption>, <init input>, [<callback>] )

            #input project name
            (
                "project_name",                                             
                LOC["CREATE_PROJECT"] + ">" +  LOC[ "INPUT_PROJECT_NAME" ], 
                LOC["INPUT_PROJECT_NAME"],                                  
                "",                                                         
                None                                                        
            ),
            #input project directory
            (
                "project_directory",                                       
                LOC["CREATE_PROJECT"] + ">" +  LOC[ "INPUT_PROJECT_DIR" ], 
                LOC["INPUT_PROJECT_DIR"],                                  
                ( lambda : os.path.join( 
                    len( CFG.get( "work_space") ) and CFG.get("work_space") or default_directory,
                    self["project_name"] 
                ).replace("\\","/") ),                                                     
                [ self.__createProjectDestory, self.__createProjectConfig, self.__openProject ]                             
            )
        ] )
        
        self.__showInputPanel()
Ejemplo n.º 3
0
    def __replaceTag( self ):
        
        cfg          = self.__config["release"]
        ig_file_exts = cfg["ignore_file_exts"]
        data         = { "project_name" : self.__config["name"] }
        data.update( cfg["variables"] )
        tobj         = StringTemple( "", data )
        DATE_FORMAT  = LOC["DATE_FORMAT"]
        TIME_FOMAT   = "%H:%M:%S"
        DTIME_FORMAT = "%s %s" % ( DATE_FORMAT, TIME_FOMAT )
        replace_scope= CFG.get("replace_scope")

        #DEBUG
        MESSAGE(
            "   IG_FILE_EXTS : %s" % ( ig_file_exts ),
            c      = DEBUG,
            prefix = ""
        )

        for path in self.__files:
            ext = os.path.splitext( path )[1].lower()
            rpath = path.replace( os.path.dirname( self.__releasepath ), "" )
            if ext in ig_file_exts:
                MESSAGE( "   [IGNORE]" + rpath, c = DEBUG, prefix = "" )
                continue

            MESSAGE( "   [REPLACE]" + rpath, c = DEBUG, prefix = "" )
                
            localtime = time.localtime()
            tobj.expanData( {
                "FILE" : os.path.basename( path ),
                "PATH" : os.path.dirname( path ),
                "MDATE": time.strftime( DTIME_FORMAT, time.localtime( os.path.getctime( path ) ) ),
                "TIME" : time.strftime( TIME_FOMAT  , localtime ),
                "DATE" : time.strftime( DATE_FORMAT , localtime )
            } )

            temp    = ""
            with open( path, "r" )as fobj: temp += fobj.read()
            size    = len( temp )
            #temp    = temp.decode("utf8")
            content = ""
            for item in replace_scope:
                if ext not in item["file_ext"]: continue
                
                scopes  = []
                start   = 0
                pattern = re.compile( item["pattern"] )
                content = ""
                tobj.setTemple( "" )
                while start < size:
                    region = re.search( pattern, temp[start:] )
                    if region:
                        offset_start = start + region.start()
                        offset_end   = start + region.end()
                       # print offset_start, offset_end
                        part         = temp[ offset_start:offset_end ]
                        space        = temp[ start:offset_start ]
                        scopes.append( part )
                        if re.search( project_release.WRITESPACE_RE_PATTERN, space ):
                            tobj.expanTemple( space + part )
                        else:
                            content += tobj.parse() + temp[ start:offset_start ]
                            tobj.setTemple( part )
                            
                        start = offset_end
                    
                    else:
                        break
                content += tobj.parse() + temp[ start: ]
                #content = content.encode("utf8")
                #DEBUG
                if DEBUG:
                    MESSAGE( 
                        "            %s\n"
                        "            %s\n"
                        "            ---REPLACE SCOPE---\n"
                        "            %s\n" 
                        "            -------" % ( 
                            item["pattern"], 
                            ",".join( item["file_ext"] ),
                            "\n            ".join( [
                                re.sub( "\n", "\n            ", scope.decode("utf8") ) \
                                for scope in scopes
                            ] )
                        ),
                        c = DEBUG, 
                        prefix = "" 
                    )
            if content:
                try:
                    fobj = open( path, "w" ) 
                    fobj.write( content )
                except IOError:
                    raise IOError
                finally:
                    fobj.close() 
Ejemplo n.º 4
0
class JProjectCreateCommand( sublime_plugin.WindowCommand ):
    """JProjectCreateCommand 命令 实现了项目的创建和自动打开创建的项目"""

    def run( self ):
        #将LOC GFG DLOC等这些变量定义到当前模块 
        JProject.moduleInit( __name__ )

        self.__dict         = {
            "project_name"      : "",
            "project_directory" : ""
        }

        self.__project_name = ""
        self.__projectconfig= os.path.join( PPATH, "project.config" )
        default_directory   = os.path.expanduser( "~\\My Documents\\" )
        self.__input        = None
        self.__terr         = StringTemple( "", {} )

        #请求输入队列
        self.__iqueue       = Queue( 0, [
            #( <property>, <status message>, <caption>, <init input>, [<callback>] )

            #input project name
            (
                "project_name",                                             
                LOC["CREATE_PROJECT"] + ">" +  LOC[ "INPUT_PROJECT_NAME" ], 
                LOC["INPUT_PROJECT_NAME"],                                  
                "",                                                         
                None                                                        
            ),
            #input project directory
            (
                "project_directory",                                       
                LOC["CREATE_PROJECT"] + ">" +  LOC[ "INPUT_PROJECT_DIR" ], 
                LOC["INPUT_PROJECT_DIR"],                                  
                ( lambda : os.path.join( 
                    len( CFG.get( "work_space") ) and CFG.get("work_space") or default_directory,
                    self["project_name"] 
                ).replace("\\","/") ),                                                     
                [ self.__createProjectDestory, self.__createProjectConfig, self.__openProject ]                             
            )
        ] )
        
        self.__showInputPanel()


    def __showInputPanel( self, new = True ):
        if new:
            if self.__iqueue.empty():return None
            self.__input = self.__iqueue.get()
        elif self.__input == None:
            return None

        message( self.__input[1] )
        
        initinput = self.__input[3]
        if initinput and type(initinput) != str:
            initinput = initinput()
        
        self.window.show_input_panel( 
            self.__input[2],
            initinput, 
            self.__onInputDone, 
            None, 
            None 
        )


    def __onInputDone( self, instr ):
        message( LOC["WAIT_PLEASE"] )
        while True:
            if len(instr) == 0:
                self.__showInputPanel(False)
                return
            break
        self[self.__input[0]] = instr
        callbacks = self.__input[4]

        try:
            if callbacks:
                    for callback in callbacks:
                        callback()
            self.__showInputPanel()
        except Exception, e:
            sublime.error_message( self.__terr.parse() )
            self.__terr.setTemple("")
            message( "REAL-ERROR: " + str(e), c = DEBUG )
            return None