RunAtFirst.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from Tkinter import *
00004 from tkFont import *
00005 import tkMessageBox, os.path, string
00006 import tkSimpleDialog
00007 import tkCommonDialog
00008 import time
00009 import re
00010 import thread
00011 import sys
00012 
00013 default_searchdir="C:\\Program Files"
00014 
00015 property_sheet=os.path.dirname(sys.argv[0]) + "\\OpenRTM-aist.vsprops"
00016 
00017 widlist = ["ace_root", "ace_inc", "ace_lib",
00018            "omni_root", "omni_bin", "omni_inc", "omni_lib"]
00019 
00020 jwin_title = "OpenRTM-aist-win32 ビルド環境設定"
00021 win_title  = "OpenRTM-aist-win32 Build Environment Setting"
00022 
00023 jexplain = """OpenRTM-aistをビルドするために必要な環境を設定します。下記の項目に必要な情報を入力して、プロパティシート生成ボタンを押してください。"""
00024 
00025 explain = """Setting up OpenRTM-aist build environment. Please input information to the following forms, and push Generate button to generate property sheet"""
00026 
00027 jsearch_expln = """自動的に検索することもできます。検索するディレクトリを入力して「検索」ボタンを押してください。
00028 検索には数分かかることがあります。"""
00029 search_expln = """Automatic search. Input search directory and push [Search] button. 
00030 It may take a few minutes."""
00031 
00032 jsearch_dir = "検索ディレクトリ"
00033 search_dir = "Search Directory"
00034 
00035 jsbutton="検索"
00036 sbutton="Search"
00037 
00038 jdirname_error="ディレクトリが見つかりません。"
00039 dirname_error="DIrectory not found."
00040 
00041 
00042 entries = {
00043     "ace_root" : \
00044         {"label": "ACE directory",
00045          "expln": "The ACE_wrapper directory a.k.a ACE_ROOT directory."},
00046     "ace_inc"  : \
00047         {"label": "ACE include directory",
00048          "expln": "The directory in which ace/ACE.h exists."},
00049     "ace_lib"  : \
00050         {"label": "ACE lib directory",
00051          "expln": "The directory in which ACE.LIB exists."},
00052     "omni_root": \
00053         {"label": "omniORB directory",
00054          "expln": "The omniORB directory in which bin, include, lib dirs exist."},
00055     "omni_bin" : \
00056         {"label": "omniORB bin directory",
00057          "expln": "The directory in which omniidl exists."},
00058     "omni_inc" : \
00059         {"label": "omniORB include directory",
00060          "expln": "The directory in which omniORB4/CORBA.h exists"},
00061     "omni_lib" : \
00062         {"label": "omniORB lib directory",
00063          "expln": "The directory in wihch omniORB407_rt.lib exists."}
00064     }
00065 
00066 jentries = {
00067     "ace_root" : \
00068         {"label": "ACEディレクトリ",
00069          "expln": "通常はACE_wrapperディレクトリの位置を指定してください。"},
00070     "ace_inc"  : \
00071         {"label": "ACE include ディレクトリ",
00072          "expln": "ace/ACE.hがあるディレクトリを指定してください。"},
00073     "ace_lib"  : \
00074         {"label": "ACE lib ディレクトリ",
00075          "expln": "ACE.LIBがある場所を指定してください。"},
00076     "omni_root": \
00077         {"label": "omniORBディレクトリ",
00078          "expln": "omniORBのディレクトリ(下にbin, include, libがある)を指定してください。"},
00079     "omni_bin" : \
00080         {"label": "omniORB bin ディレクトリ",
00081          "expln": "omniidlがあるディレクトリを指定してください。"},
00082     "omni_inc" : \
00083         {"label": "omniORB include ディレクトリ",
00084          "expln": "omniORB4/CORBA.hがあるディレクトリを指定してください。"},
00085     "omni_lib" : \
00086         {"label": "omniORB lib ディレクトリ",
00087          "expln": "omniORB407_rt.libなどがあるディレクトリを指定してください。"}
00088     }
00089 
00090 
00091 jgbutton="生成"
00092 gbutton="Generate"
00093 
00094 jgen_label="プロパティシート:"
00095 gen_label="Property Sheet:"
00096 
00097 jgen_expln = """OpenRTM-aistソースディレクトリの下にOpenRTM-aist.vspropsというファイル名でプロパティシートを生成する必要があります。ACEやomniORBの各種パスおよびプロパティシートのディレクトリが正しければ生成ボタンを押してください。"""
00098 
00099 gen_expln = """Property sheet named OpenRTM-aist.vsprops should exist under OpenRTM-aist source directory. Please confirm directories of ACE, omniORB and property sheet and push Generate button."""
00100 
00101 prop_sheet = """<?xml version="1.0" encoding="shift_jis"?>
00102 <VisualStudioPropertySheet
00103         ProjectType="Visual C++"
00104         Version="8.00"
00105         Name="OpenRTM-aist-0.4"
00106         >
00107         <Tool
00108                 Name="VCCLCompilerTool"
00109                 AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\\rtm\idl&quot;;&quot;$(ace_include)&quot;;&quot;$(omni_include)&quot;;.;..\..;..;..\..\.."
00110         />
00111         <Tool
00112                 Name="VCLinkerTool"
00113                 AdditionalLibraryDirectories="&quot;$(SolutionDir)\\bin&quot;;&quot;$(ace_libdir)&quot;;&quot;$(omni_libdir)&quot;"
00114         />
00115         <UserMacro
00116                 Name="ace_root"
00117                 Value="%s"
00118         />
00119         <UserMacro
00120                 Name="omni_root"
00121                 Value="%s"
00122         />
00123         <UserMacro
00124                 Name="rtm_root"
00125                 Value="$(SolutionDir)"
00126         />
00127         <UserMacro
00128                 Name="ace_include"
00129                 Value="%s"
00130         />
00131         <UserMacro
00132                 Name="ace_libdir"
00133                 Value="%s"
00134         />
00135         <UserMacro
00136                 Name="omni_include"
00137                 Value="%s"
00138         />
00139         <UserMacro
00140                 Name="omni_libdir"
00141                 Value="%s"
00142         />
00143         <UserMacro
00144                 Name="omni_bin"
00145                 Value="%s"
00146         />
00147         <UserMacro
00148                 Name="rtm_includes"
00149                 Value="$(SolutionDir);$(SolutionDir)\\rtm\idl;$(ace_include);$(omni_include);.;..\..\\"
00150         />
00151         <UserMacro
00152                 Name="rtm_libdir"
00153                 Value="$(SolutionDir)\\bin;$(ace_libdir);$(omni_libdir);."
00154         />
00155         <UserMacro
00156                 Name="rtm_path"
00157                 Value="$(SolutionDir)\\bin;$(SolutionDir)\\build;&quot;$(omni_bin)&quot;"
00158         />
00159 </VisualStudioPropertySheet>
00160 """
00161 
00162 jisdir_error = "同名のディレクトリが存在します。 "
00163 isdir_error = "The Directory of a same name exists. "
00164 
00165 jfile_exists = "ファイルが存在します。上書きしますか? "
00166 file_exists = "The file already exists. Overwrite? "
00167 
00168 jfile_gened = "ファイルを生成しました。"
00169 file_gened = "File generated."
00170 
00171 
00172 def search(path, fnames, results):
00173     try:
00174         flist = os.listdir(path)
00175     except:
00176         return
00177 
00178     mp = []
00179     for fn in fnames:
00180         mp.append(re.compile(fn))
00181 
00182     for f in flist:
00183         fullpath = path + "/" + f
00184         if os.path.isfile(fullpath):
00185 #            for fname in fnames:
00186 #                if f == fname:
00187 #                    results[fname] = fullpath
00188             i = 0
00189             for m in mp:
00190                 if m.match(f):
00191                     results[fnames[i]] = fullpath
00192                 i += 1
00193         elif os.path.isdir(fullpath):
00194             res = search(fullpath, fnames, results)
00195     return
00196 
00197 
00198 def j(str, encoding="cp932"):
00199   return unicode(str, encoding).encode("utf8")
00200 
00201 
00202 
00203 class App(Frame):
00204     def init(self):
00205         self.setlang()
00206         self.width=512
00207         
00208         self.f8  = Font(weight=NORMAL, family="", size=8) 
00209         self.f9  = Font(weight=NORMAL, family="", size=9) 
00210         self.f10 = Font(weight=NORMAL, family="", size=10) 
00211         self.f11 = Font(weight=NORMAL, family="", size=11) 
00212 
00213         self.master.title(self.win_title)
00214         
00215         f = Frame()
00216 
00217         # 説明
00218         self.expw = Label(f, text=self.explain, font=self.f11, \
00219                               justify=LEFT, wraplength=self.width)
00220         self.expw.pack(side=TOP, anchor=W, padx=3, pady=3)
00221 
00222         self.search_frame(f)
00223         self.entries_frame(f)
00224         self.gen_frame(f)
00225         f.pack(side=TOP, anchor=E, pady=5)
00226 
00227     def setlang(self):
00228         if time.tzname[0].find("東京") or time.tzname[0].find("JST"):
00229             self.ent = jentries
00230             self.win_title = j(jwin_title)
00231             self.explain = j(jexplain)
00232             self.search_expln = j(jsearch_expln)
00233             self.search_dir = j(jsearch_dir)
00234             self.search_button = j(jsbutton)
00235             self.gen_button = j(jgbutton)
00236             self.dirname_error=j(jdirname_error)
00237             self.gen_label = j(jgen_label)
00238             self.gen_expln = j(jgen_expln)
00239             self.isdir_error = j(jisdir_error)
00240             self.file_exists = j(jfile_exists)
00241             self.file_gened = j(jfile_gened)
00242         else:
00243             self.ent = entries
00244             self.win_title = win_title
00245             self.explain = explain
00246             self.search_expln = search_expln
00247             self.search_dir = search_dir
00248             self.search_button = sbutton
00249             self.gen_button = gbutton
00250             self.dirname_error=dirname_error
00251             self.gen_label = gen_label
00252             self.gen_expln = gen_expln
00253             self.isdir_error = isdir_error
00254             self.file_exists = file_exists
00255             self.file_gened = file_gened
00256 
00257     def search_frame(self, f):
00258         frame = Frame(f, relief=Tkinter.GROOVE, bd=2)
00259         dummyw = Frame(frame, width=self.width)
00260         dummyw.pack(side=TOP)
00261         frame.pack(side=TOP)
00262         # 自動検索の説明
00263         self.search_explnw = Label(frame, text=self.search_expln, \
00264                                        wraplength=self.width, justify=LEFT,\
00265                                        font=self.f11)
00266         self.search_explnw.pack(side=TOP, anchor=W, padx=0)
00267 
00268         f1 = Frame(frame, width=self.width)
00269         f1.pack(side=TOP)
00270 
00271         self.search_labelw = Label(f1, text=self.search_dir, font=self.f11)
00272         self.search_labelw.pack(side=LEFT, anchor=W)
00273         self.search_dirw   = Entry(f1, width=40, font=self.f11)
00274         self.search_dirw.delete(0)
00275         self.search_dirw.insert(0, default_searchdir)
00276         self.search_dirw.pack(side=LEFT, anchor=W, padx=5, pady=5)
00277         self.search_button = Button(f1, text=self.search_button,
00278                                     command=self.search, font=self.f10)
00279         self.search_button.pack(side=LEFT, anchor=W, padx=10, pady=5)
00280         f1.pack(side=TOP, anchor=W)
00281 
00282     def entries_frame(self, f):
00283         frame = Frame(f, relief=GROOVE, bd=2)
00284         dummyw = Frame(frame, width=self.width)
00285         dummyw.pack(side=TOP)
00286         frame.pack(side=TOP)
00287         for w in widlist:
00288             self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["label"]), \
00289                                          font=self.f11, wraplength='10c')
00290             self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10)
00291             self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["expln"]), \
00292                                          font=self.f9, wraplength='10c')
00293             self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10)
00294             self.ent[w]["wid"] = Entry(frame, width=80, font=self.f9)
00295             self.ent[w]["wid"].pack(side=TOP, anchor=NW, padx=10, pady=5)
00296 
00297     def gen_frame(self, f):
00298         frame = Frame(f, relief=Tkinter.GROOVE, bd=2)
00299         dummyw = Frame(frame, width=self.width)
00300         dummyw.pack(side=TOP)
00301         frame.pack(side=TOP)
00302 
00303         self.gen_expw = Label(frame, text=self.gen_expln, \
00304                                        wraplength=self.width, justify=LEFT,\
00305                                        font=self.f11)
00306         self.gen_expw.pack(side=TOP, anchor=W, padx=0)
00307 
00308         f1 = Frame(frame)
00309         self.gen_labelw = Label(f1, text=self.gen_label, font=self.f11)
00310         self.gen_labelw.pack(side=LEFT, anchor=W, padx=3, pady=3)
00311         self.gen_entryw = Entry(f1, width=40, \
00312                                     text="OpenRTM-aist.vsprops", font=self.f11)
00313         self.gen_entryw.insert(0, property_sheet)
00314         self.gen_entryw.pack(side=LEFT, anchor=W, padx=5, pady=5)
00315         self.gbuttonw = Button(f1, text=self.gen_button, font=self.f10,
00316                                command=self.generate)
00317         self.gbuttonw.pack(side=LEFT, anchor=W, padx=3, pady=3)
00318         f1.pack(side=TOP, anchor=W)
00319 
00320 
00321     def quit(self):
00322         self.master.destroy()
00323 
00324     def generate(self):
00325         ace_inc = self.ent["ace_inc"]["wid"].get()
00326         ace_lib = self.ent["ace_lib"]["wid"].get()
00327         ace_dirs = [ace_inc, ace_lib]
00328 
00329         omni_bin = self.ent["omni_bin"]["wid"].get()
00330         omni_inc = self.ent["omni_inc"]["wid"].get()
00331         omni_lib = self.ent["omni_lib"]["wid"].get()
00332         omni_dirs = [omni_bin, omni_inc, omni_lib]
00333             
00334         ace_root, ace_paths   = self.common_path(ace_dirs)
00335         omni_root, omni_paths = self.common_path(omni_dirs)
00336 
00337         print ace_paths
00338         print ace_root
00339         print ace_inc
00340         if ace_paths[0] == "/" and ace_paths[1] == "/lib/":
00341             ace_inc = "$(ace_root)"
00342             ace_lib = "$(ace_root)/lib"
00343 
00344         if omni_paths[0] == "/bin/x86_win32/" and \
00345            omni_paths[1] == "/include/"       and \
00346            omni_paths[2] == "/lib/x86_win32/"     :
00347             omni_bin = "$(omni_root)/bin/x86_win32"
00348             omni_inc = "$(omni_root)/include"
00349             omni_lib = "$(omni_root)/lib/x86_win32"
00350 
00351         ace_root  = re.sub("/", "\\\\", ace_root)
00352         omni_root = re.sub("/", "\\\\", omni_root)
00353         ace_inc   = re.sub("/", "\\\\", ace_inc)
00354         ace_lib   = re.sub("/", "\\\\", ace_lib)
00355         omni_bin  = re.sub("/", "\\\\", omni_bin)
00356         omni_inc  = re.sub("/", "\\\\", omni_inc)
00357         omni_lib  = re.sub("/", "\\\\", omni_lib)
00358 
00359         fname = self.gen_entryw.get()
00360 
00361         if os.path.isdir(fname):
00362             tkMessageBox.showerror(title=self.isdir_error, 
00363                                    message=self.isdir_error + fname)
00364             return
00365 
00366         if os.path.isfile(fname):
00367             if not tkMessageBox.askyesno(title=self.file_exists, 
00368                                          message=self.file_exists + fname):
00369                 return
00370 
00371         f = open(fname, "w")
00372         f.write(prop_sheet % \
00373                     (ace_root, omni_root, \
00374                          ace_inc, ace_lib, \
00375                          omni_inc, omni_lib, omni_bin))
00376         f.close()
00377         tkMessageBox.showinfo(title=self.file_gened,
00378                               message=self.file_gened + fname)
00379         return
00380 
00381     def search(self):
00382         w = {
00383             "ACE.h"               : ["ace_inc", "ace/ACE.h"],
00384             "ACE.lib"             : ["ace_lib", "ACE.lib"],
00385             "omniidl.exe"         : ["omni_bin", "omniidl.exe"],
00386             "omniORB.h"           : ["omni_inc", "omniORB4/omniORB.h"],
00387             "omniORB[0-9]+_rt.lib": ["omni_lib", "omniORB[0-9]+_rt.lib"]
00388             }
00389         res = {}
00390         dirname = self.search_dirw.get()
00391         if os.path.isdir(dirname):
00392 #            th = thread.start_new_thread(search, (dirname, w.keys(), res))
00393             search(dirname, w.keys(), res)
00394         else:
00395             tkMessageBox.showerror(title=self.dirname_error, 
00396                                    message=self.dirname_error + dirname)
00397             return
00398 
00399         # 検索結果をEntryにセット
00400         for f in w.keys():
00401             if res.has_key(f):
00402                 l = len(self.ent[w[f][0]]["wid"].get())
00403                 self.ent[w[f][0]]["wid"].delete(0, l)
00404                 t = re.sub(re.compile(w[f][1]), "", res[f])
00405                 self.ent[w[f][0]]["wid"].insert(0, t)
00406 
00407         # 検索結果を取得
00408         ace_dirs = [
00409             self.ent["ace_inc"]["wid"].get(),
00410             self.ent["ace_lib"]["wid"].get()
00411             ]
00412         
00413         omni_dirs = [
00414             self.ent["omni_bin"]["wid"].get(),
00415             self.ent["omni_inc"]["wid"].get(),
00416             self.ent["omni_lib"]["wid"].get()
00417             ]
00418             
00419         # 共通パスを取得
00420         ace_root = ""
00421         if ace_dirs[0] != "" or ace_dirs[1] != "":
00422             ace_root, ace_paths   = self.common_path(ace_dirs)
00423 
00424         omni_root = ""
00425         if omni_dirs[0] != "" or \
00426                 omni_dirs[1] != "" or \
00427                 omni_dirs[2] != "":
00428             omni_root, omni_paths = self.common_path(omni_dirs)
00429 
00430 
00431         if omni_root != "":
00432             l = len(self.ent["omni_root"]["wid"].get())
00433             self.ent["omni_root"]["wid"].delete(0, l)
00434             self.ent["omni_root"]["wid"].insert(0, omni_root)
00435 
00436         # ACE_ROOT, OMNI_ROOTをEntryにセット
00437         if ace_root != "":
00438             l = len(self.ent["ace_root"]["wid"].get())
00439             self.ent["ace_root"]["wid"].delete(0, l)
00440             self.ent["ace_root"]["wid"].insert(0, ace_root)
00441 
00442         return
00443 
00444 
00445     def common_path_len(self, plist):
00446         for i in range(len(plist[0])): # ディレクトリ名を比較
00447             dirname = plist[0][i]
00448             for j in range(1, len(plist)):
00449                 if dirname != plist[j][i]:
00450                     return i
00451         return
00452 
00453     def common_path_split(self, paths):
00454         plist = []
00455         for p in paths:
00456             plist.append(p.split("/"))
00457         return plist
00458 
00459     def common_path(self, paths):
00460         plist  = self.common_path_split(paths)
00461         comlen = self.common_path_len(plist)
00462 
00463         compath=""
00464         for i in range(comlen):
00465             compath += plist[0][i]
00466             if i != comlen - 1:
00467                 compath += "/"
00468 
00469         diff_paths = [""] * len(paths)
00470         for i in range(len(paths)):
00471             diff_paths[i] = ""
00472             for j in range(comlen, len(plist[i])):
00473                 diff_paths[i] += "/" + plist[i][j]
00474 
00475         return compath, diff_paths
00476 
00477 
00478 
00479     def __init__(self, master=None):
00480         Frame.__init__(self, master)
00481         self.pack();    self.init()
00482 
00483 
00484 if __name__ == "__main__": app = App();  app.mainloop()
00485 # end.
00486 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07