Commits

Anonymous committed e503118

contl10n01: windows fixes, fetch sdf also from local filesystem, first implementation of bad lang propagation

  • Participants
  • Parent commits d549716

Comments (0)

Files changed (4)

l10ntools/scripts/tool/botctrl.py

         return self._locks[key]
     
     def set_hint(self, hint):
-        with self._hint_lock:
-            self._hint = hint
+        self._hint_lock.acquire()
+        self._hint = hint
+        self._hint_lock.release()
 
     def get_hint(self):
         hint = ""
-        with self._hint_lock:
-            hint = self._hint
+        self._hint_lock.acquire()
+        hint = self._hint
+        self._hint_lock.release()
         return hint
         
     def set_state(self, state):
-        with self._state_lock:
-            self._state = state
+        self._state_lock.acquire()
+        self._state = state
+        self._state_lock.release()
             
     def get_state(self):
         state = ""
-        with self._state_lock:
-            state = self._state
+        self._state_lock.acquire()
+        state = self._state
+        self._state_lock.release()
         return state
 
     def set_bad_langs_in(self, langs):
-        with self._bad_langs_in:
-            self._bad_langs_in = langs
-            
+        self._bad_langs_in.acquire()
+        self._bad_langs_in = langs
+        self._bad_langs_in.release()
+
     def get_bad_langs_in(self):
         langs = []
-        with self._bad_langs_in_lock:
-            langs = self._bad_langs_in
+        self._bad_langs_in_lock.acquire()
+        langs = self._bad_langs_in
+        self._bad_langs_in_lock.release()
         return langs
 
     def set_bad_langs_out(self, langs):
-        with self._bad_langs_out_lock:
-            self._bad_langs_out = langs
-            
+        self._bad_langs_out_lock.acquire()
+        self._bad_langs_out = langs
+        self._bad_langs_out_lock.release()
+
     def get_bad_langs_out(self):
         langs = []
-        with self._bad_langs_out_lock:
-            langs = self._bad_langs_out
+        self._bad_langs_out_lock.acquire()
+        langs = self._bad_langs_out
+        self._bad_langs_out_lock.release()    
         return langs
         
 class BotModel():    
         # set_compile_state()
         if bot_signal == ContL10nStatus.HAS_ERROR:
             return HasErrorS()
+
+        bad_langs = self.botctrl._bot_model.contl10n_status.get_bad_langs_in()
+        # Stop current build
+        BState.botctrl._contl10n.stop()
+        del BState.botctrl._contl10n
+        time.sleep(2)
+        state_cfg = StateCfg()
+        
+        # Change languages
+        if state_cfg.has_option("MERGE","files_modified"):
+            mod_files = self.unpack_list(state_cfg.get("MERGE","files_modified"))
+        if state_cfg.has_option("MERGE","new_files"):
+            new_files = self.unpack_list(state_cfg.get("MERGE","new_files"))
+        
+        chg_mod_files = set(mod_files) - set(bad_langs)
+        chg_new_files = set(new_files) - set(bad_langs)
+        state_cfg.set("MERGE","files_modified",chg_mod_files)
+        state_cfg.set("MERGE","new_files",chg_new_files)
+        
+        # TODO make this part of the ToolCfg class
+        try:
+            #print "Writing to " +os.getcwd()+"/state.cfg"
+            fh = open("state.cfg","wb")
+            state_cfg.write(fh)
+            fh.flush()
+        except IOError:
+            print "ERROR: Can not write file state.cfg!!!"
+            sys.exit(-1)
+        fh.close()
+
+        # Start new build
+        BState.botctrl._contl10n = ContL10n(BState.botctrl._bot_model, BState.botctrl._state_cfg, self.log) 
+        BState.botctrl._contl10n.setDaemon(True)
+
+        #if BState.botctrl.is_mainbot:
+        #    BState.botctrl._contl10n.set_state_table(BotController.init_main_finish_state_table(),"init_main_finish_state_table")
+        #else:
+        #    BState.botctrl._contl10n.set_state_table(BotController.init_upload_state_table(),"init_upload_state_table")
+        # Set first state
+        #BState.botctrl._contl10n.set_state()
+        
+        BState.botctrl._bot_model.contl10n_status.set_state(ContL10nStatus.RUNNING)
+        BState.botctrl._contl10n.start()
+        
         botctrl._model.contl10n_status.set_state(self._model.contl10n_status.RUNNING)
         return RunningS()
 

l10ntools/scripts/tool/commands.py

         self._dest_path   = tool_cfg.get("Download Server", "dest_path")
         self._server_user = tool_cfg.get("Download Server", "server_user")
         self._server_keyfile = tool_cfg.get("Download Server", "server_keyfile")
+        self._filesystem   = tool_cfg.get("Download Server", "filesystem") 
         self._log = log 
         
     def do(self, env):
-        cmd = "scp -i %s %s@%s %s" % (self._server_keyfile, self._server_user, self._server_url+":"+self._server_path, self._dest_path)
-        #self._log.info("cmd="+cmd)
         utils.Util.makedirs(self._dest_path, self._log)
-        scp_rc, stdout_v, stderr_v = utils.Util.exe(cmd, self._log)
+        if not self._server_url == "" and not self._server_path == "":
+            cmd = "scp -i %s %s@%s %s" % (self._server_keyfile, self._server_user, self._server_url+":"+self._server_path, self._dest_path)
+            self._log.info("cmd="+cmd)
+            scp_rc, stdout_v, stderr_v = utils.Util.exe(cmd, self._log)
+        if not self._filesystem == "":
+            filelist = glob.glob(self._filesystem)
+            for file in filelist:
+                utils.Util.copyfile(file, self._dest_path)
 
     def post(self, tool_cfg, state_cfg, env):
         # write status into state_cfg
         test_files = self._cws_root + "/" + self._l10n_path + "/*/localize.sdf"
         file_list = glob.glob(test_files)
         errmsg = "Can not commit '"+str(" ".join(file_list))+"'\n"
-        out_v = utils.Util.hg_cmd(commands.status, self._log, errmsg, myui, repo, *file_list)
+        opts = { "all": "True" }
+        out_v = utils.Util.hg_cmd(commands.status, self._log, errmsg, myui, repo, *file_list, **opts)
+        #returncode, out_v , err_v = utils.Util.exe("hg status "+" ".join(file_list), self._log)
         mod_files = list()
         new_files = list()
         for line in out_v.split("\n"):
             lang_list.append("en-US_" + "_".join(list)) 
             list = []
 
-        with open(self._cws_root + "/instsetoo_native/util/pack.lst","wb") as fh:
-                fh.write(pack_lst_pre + "|".join(lang_list) + pack_lst_post)
+        try:
+            fh = open(self._cws_root + "/instsetoo_native/util/pack.lst","wb")
+            fh.write(pack_lst_pre + "|".join(lang_list) + pack_lst_post)
+            fh.close
+        except IOError:
+            self._log.die("Can not write file "+self._cws_root + "/instsetoo_native/util/pack.lst")
 
     def do(self, env):
         # REMOVEME
         
         # setup source_config
         utils.Util.exe("perl "+self._cws_root + "/solenv/bin/build.pl product=full --genconf --removeall", self._log, env)
-        utils.Util.exe("perl "+self._cws_root + "/solenv/bin/build.pl product=full --genconf --add --from l10n", self._log, env)
+        utils.Util.exe("perl "+self._cws_root + "/solenv/bin/build.pl product=full --genconf --add l10n", self._log, env)
+        utils.Util.exe("perl "+self._cws_root + "/solenv/bin/build.pl product=full --genconf --add readlicense_oo", self._log, env)
+        #utils.Util.exe("perl "+self._cws_root + "/solenv/bin/build.pl product=full --genconf --add --from l10n", self._log, env)
         
         env["WITH_LANG"]=str(" ".join(self._files_modified + self._new_files))
         

l10ntools/scripts/tool/contl10n.py

 import ConfigParser, os, logging, sys, utils
 from commands import GetSdf, Merge, Compile, Upload, CommitSDF, SetStati, Start, End, PreBuild, PrepareCWS
 from utils import Util, Env, ContL10nLogger, CustomLogger
-from botctrl import BotModel
+from botctrl import BotModel, BotController
 
 class CContL10n:
     
         # Init config
         self._tool_cfg = utils.ToolCfg()
         self._state_cfg = utils.StateCfg()
-        #self._tool_cfg = ConfigParser.ConfigParser()
-        #self._state_cfg = ConfigParser.ConfigParser()
         self._bot_model = BotModel()
         self._state = None 
         self.init_state_table()
-        #self._tool_cfg.read("tool.cfg")
         # Init environment
-        self._log = utils.ContL10nLogger(utils.ToolCfg(), utils.StateCfg()).get_logger("l10nbot") #ContL10nLogger(self._tool_cfg, self._state_cfg, self._bot_model).get_logger(self._tool_cfg.get("BOT","bot_name"))
+        self._log = utils.ContL10nLogger(utils.ToolCfg(), utils.StateCfg()).get_logger("l10nbot")
         self._log.info("Starting ....")
         self._env = Env(self._tool_cfg.get("BOT","configure_string"), self._tool_cfg.get("BOT","setsolar_string"), 
                         self._tool_cfg.get("CWS","cws_root"), self._tool_cfg.get("BOT","use_env"), self._log)
         self.process()
         
     def init_state_table(self):
-        # TODO: read this state table from tool_cfg and not hardcoded
-        # TODO: return next state from state so it is possible to switch on condition
-        self._state_table = dict({ 
+        if BotController.is_mainbot():
+            self._state_table = dict({ 
                             "START":    State(Start(),     "PREPARECWS"),  
                             "PREPARECWS": State(PrepareCWS(), "MERGE"),
                             "PREBUILD": State(PreBuild(),  "MERGE"),
                             "SETSTATI": State(SetStati(),  "END"),
                             "END":      State(End(),       "END") })
  
+        else:
+            self._state_table = dict({ 
+                            "START":    State(Start(),     "GETSDF"),  
+                            "PREBUILD": State(PreBuild(),  "MERGE"),
+                            "GETSDF":   State(GetSdf(),    "MERGE"),
+                            "MERGE":    State(Merge(),     "COMPILE"),
+                            "COMPILE":  State(Compile(),   "UPLOAD"),
+                            "UPLOAD":   State(Upload(),    "END"),
+                            "END":      State(End(),       "END") })
+ 
+ 
 
     def set_state(self,state):
         if state is None:

l10ntools/scripts/tool/masterctrl.py

             ip_file_cfg.add_section("Runtime")
         ip_file_cfg.set("Runtime", "server_ip", ip)
         
-        with open(ip_file,"wb") as fh:
+        try:
+            fh = open(ip_file,"wb") 
             ip_file_cfg.write(fh)
+            fh.close()
+        except IOError:
+            self._log.die("Can not weite ip_file")
         #if not self._state_cfg.has_section("Runtime"):
         #    self._state_cfg.add_section("Runtime")
         #self._state_cfg.set("Runtime","server_ip",ip)
     def run(self):
         while not self._stop_event.is_set():
             while not self._event.wait(self._interval) and self.is_alive():
-                with self._lock: 
-                    self._life_time = self._life_time - 1
+                self._lock.acquire()
+                self._life_time = self._life_time - 1
+                self._lock.release()
             
     def stop(self):
         self._stop_event.set()
 
     def is_alive(self):
-        with self._lock:
-            value = (self._life_time > 0)
+        self._lock.acquire()
+        value = (self._life_time > 0)
+        self._lock.release()
         return value
 
     def set_alive(self):
         self.__reset_life_time()
 
     def __reset_life_time(self):
-        with self._lock: 
-            self._life_time = self._default_life_time
-
+        self._lock.acquire()
+        self._life_time = self._default_life_time
+        self._lock.release()
       
 class bot_fitness(threading.Thread):
     DEFAULT_LIFE_TIME = 120 # seconds