RunAtFirst.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from Tkinter import *
4 from tkFont import *
5 import tkMessageBox, os.path, string
6 import tkSimpleDialog
7 import tkCommonDialog
8 import time
9 import re
10 import thread
11 import sys
12 
13 default_searchdir="C:\\Program Files"
14 
15 property_sheet=os.path.dirname(sys.argv[0]) + "\\OpenRTM-aist.vsprops"
16 
17 widlist = ["ace_root", "ace_inc", "ace_lib",
18  "omni_root", "omni_bin", "omni_inc", "omni_lib"]
19 
20 jwin_title = "OpenRTM-aist-win32 ビルド環境設定 win_title = "OpenRTM-aist-win32 Build Environment Setting" jexplain = """OpenRTM-aistをビルドするために必要な環境を設定します。下記の項目に必要な情報を入力して、プロパティシート生成ボタンを押してください。""" explain = """Setting up OpenRTM-aist build environment. Please input information to the following forms, and push Generate button to generate property sheet""" jsearch_expln = """自動的に検索することもできます。検索するディレクトリを入力して「検索」ボタンを押してください。 検索には数分かかることがあります。""" search_expln = """Automatic search. Input search directory and push [Search] button. It may take a few minutes.""" jsearch_dir = "検索ディレクトリ" search_dir = "Search Directory" jsbutton="検索" sbutton="Search" jdirname_error="ディレクトリが見つかりません。" dirname_error="DIrectory not found." entries = { "ace_root" : \ {"label": "ACE directory", "expln": "The ACE_wrapper directory a.k.a ACE_ROOT directory."}, "ace_inc" : \ {"label": "ACE include directory", "expln": "The directory in which ace/ACE.h exists."}, "ace_lib" : \ {"label": "ACE lib directory", "expln": "The directory in which ACE.LIB exists."}, "omni_root": \ {"label": "omniORB directory", "expln": "The omniORB directory in which bin, include, lib dirs exist."}, "omni_bin" : \ {"label": "omniORB bin directory", "expln": "The directory in which omniidl exists."}, "omni_inc" : \ {"label": "omniORB include directory", "expln": "The directory in which omniORB4/CORBA.h exists"}, "omni_lib" : \ {"label": "omniORB lib directory", "expln": "The directory in wihch omniORB407_rt.lib exists."} } jentries = { "ace_root" : \ {"label": "ACEディレクトリ", "expln": "通常はACE_wrapperディレクトリの位置を指定してください。"}, "ace_inc" : \ {"label": "ACE include ディレクトリ", "expln": "ace/ACE.hがあるディレクトリを指定してください。"}, "ace_lib" : \ {"label": "ACE lib ディレクトリ", "expln": "ACE.LIBがある場所を指定してください。"}, "omni_root": \ {"label": "omniORBディレクトリ", "expln": "omniORBのディレクトリ(下にbin, include, libがある)を指定してください。"}, "omni_bin" : \ {"label": "omniORB bin ディレクトリ", "expln": "omniidlがあるディレクトリを指定してください。"}, "omni_inc" : \ {"label": "omniORB include ディレクトリ", "expln": "omniORB4/CORBA.hがあるディレクトリを指定してください。"}, "omni_lib" : \ {"label": "omniORB lib ディレクトリ", "expln": "omniORB407_rt.libなどがあるディレクトリを指定してください。"} } jgbutton="生成" gbutton="Generate" jgen_label="プロパティシート:" gen_label="Property Sheet:" jgen_expln = """OpenRTM-aistソースディレクトリの下にOpenRTM-aist.vspropsというファイル名でプロパティシートを生成する必要があります。ACEやomniORBの各種パスおよびプロパティシートのディレクトリが正しければ生成ボタンを押してください。""" 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.""" prop_sheet = """<?xml version="1.0" encoding="shift_jis"?> <VisualStudioPropertySheet ProjectType="Visual C++" Version="8.00" Name="OpenRTM-aist-0.4" > <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\\rtm\idl&quot;;&quot;$(ace_include)&quot;;&quot;$(omni_include)&quot;;.;..\..;..;..\..\.." /> <Tool Name="VCLinkerTool" AdditionalLibraryDirectories="&quot;$(SolutionDir)\\bin&quot;;&quot;$(ace_libdir)&quot;;&quot;$(omni_libdir)&quot;" /> <UserMacro Name="ace_root" Value="%s" /> <UserMacro Name="omni_root" Value="%s" /> <UserMacro Name="rtm_root" Value="$(SolutionDir)" /> <UserMacro Name="ace_include" Value="%s" /> <UserMacro Name="ace_libdir" Value="%s" /> <UserMacro Name="omni_include" Value="%s" /> <UserMacro Name="omni_libdir" Value="%s" /> <UserMacro Name="omni_bin" Value="%s" /> <UserMacro Name="rtm_includes" Value="$(SolutionDir);$(SolutionDir)\\rtm\idl;$(ace_include);$(omni_include);.;..\..\\" /> <UserMacro Name="rtm_libdir" Value="$(SolutionDir)\\bin;$(ace_libdir);$(omni_libdir);." /> <UserMacro Name="rtm_path" Value="$(SolutionDir)\\bin;$(SolutionDir)\\build;&quot;$(omni_bin)&quot;" /> </VisualStudioPropertySheet> """ jisdir_error = "同名のディレクトリが存在します。 " isdir_error = "The Directory of a same name exists. " jfile_exists = "ファイルが存在します。上書きしますか? " file_exists = "The file already exists. Overwrite? " jfile_gened = "ファイルを生成しました。" file_gened = "File generated." def search(path, fnames, results): try: flist = os.listdir(path) except: return mp = [] for fn in fnames: mp.append(re.compile(fn)) for f in flist: fullpath = path + "/" + f if os.path.isfile(fullpath): # for fname in fnames: # if f == fname: # results[fname] = fullpath i = 0 for m in mp: if m.match(f): results[fnames[i]] = fullpath i += 1 elif os.path.isdir(fullpath): res = search(fullpath, fnames, results) return def j(str, encoding="cp932"): return unicode(str, encoding).encode("utf8") class App(Frame): def init(self): self.setlang() self.width=512 self.f8 = Font(weight=NORMAL, family="", size=8) self.f9 = Font(weight=NORMAL, family="", size=9) self.f10 = Font(weight=NORMAL, family="", size=10) self.f11 = Font(weight=NORMAL, family="", size=11) self.master.title(self.win_title) f = Frame() # 説明 self.expw = Label(f, text=self.explain, font=self.f11, \ justify=LEFT, wraplength=self.width) self.expw.pack(side=TOP, anchor=W, padx=3, pady=3) self.search_frame(f) self.entries_frame(f) self.gen_frame(f) f.pack(side=TOP, anchor=E, pady=5) def setlang(self): if time.tzname[0].find("東京") or time.tzname[0].find("JST"): self.ent = jentries self.win_title = j(jwin_title) self.explain = j(jexplain) self.search_expln = j(jsearch_expln) self.search_dir = j(jsearch_dir) self.search_button = j(jsbutton) self.gen_button = j(jgbutton) self.dirname_error=j(jdirname_error) self.gen_label = j(jgen_label) self.gen_expln = j(jgen_expln) self.isdir_error = j(jisdir_error) self.file_exists = j(jfile_exists) self.file_gened = j(jfile_gened) else: self.ent = entries self.win_title = win_title self.explain = explain self.search_expln = search_expln self.search_dir = search_dir self.search_button = sbutton self.gen_button = gbutton self.dirname_error=dirname_error self.gen_label = gen_label self.gen_expln = gen_expln self.isdir_error = isdir_error self.file_exists = file_exists self.file_gened = file_gened def search_frame(self, f): frame = Frame(f, relief=Tkinter.GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) # 自動検索の説明 self.search_explnw = Label(frame, text=self.search_expln, \ wraplength=self.width, justify=LEFT,\ font=self.f11) self.search_explnw.pack(side=TOP, anchor=W, padx=0) f1 = Frame(frame, width=self.width) f1.pack(side=TOP) self.search_labelw = Label(f1, text=self.search_dir, font=self.f11) self.search_labelw.pack(side=LEFT, anchor=W) self.search_dirw = Entry(f1, width=40, font=self.f11) self.search_dirw.delete(0) self.search_dirw.insert(0, default_searchdir) self.search_dirw.pack(side=LEFT, anchor=W, padx=5, pady=5) self.search_button = Button(f1, text=self.search_button, command=self.search, font=self.f10) self.search_button.pack(side=LEFT, anchor=W, padx=10, pady=5) f1.pack(side=TOP, anchor=W) def entries_frame(self, f): frame = Frame(f, relief=GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) for w in widlist: self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["label"]), \ font=self.f11, wraplength='10c') self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10) self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["expln"]), \ font=self.f9, wraplength='10c') self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10) self.ent[w]["wid"] = Entry(frame, width=80, font=self.f9) self.ent[w]["wid"].pack(side=TOP, anchor=NW, padx=10, pady=5) def gen_frame(self, f): frame = Frame(f, relief=Tkinter.GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) self.gen_expw = Label(frame, text=self.gen_expln, \ wraplength=self.width, justify=LEFT,\ font=self.f11) self.gen_expw.pack(side=TOP, anchor=W, padx=0) f1 = Frame(frame) self.gen_labelw = Label(f1, text=self.gen_label, font=self.f11) self.gen_labelw.pack(side=LEFT, anchor=W, padx=3, pady=3) self.gen_entryw = Entry(f1, width=40, \ text="OpenRTM-aist.vsprops", font=self.f11) self.gen_entryw.insert(0, property_sheet) self.gen_entryw.pack(side=LEFT, anchor=W, padx=5, pady=5) self.gbuttonw = Button(f1, text=self.gen_button, font=self.f10, command=self.generate) self.gbuttonw.pack(side=LEFT, anchor=W, padx=3, pady=3) f1.pack(side=TOP, anchor=W) def quit(self): self.master.destroy() def generate(self): ace_inc = self.ent["ace_inc"]["wid"].get() ace_lib = self.ent["ace_lib"]["wid"].get() ace_dirs = [ace_inc, ace_lib] omni_bin = self.ent["omni_bin"]["wid"].get() omni_inc = self.ent["omni_inc"]["wid"].get() omni_lib = self.ent["omni_lib"]["wid"].get() omni_dirs = [omni_bin, omni_inc, omni_lib] ace_root, ace_paths = self.common_path(ace_dirs) omni_root, omni_paths = self.common_path(omni_dirs) print ace_paths print ace_root print ace_inc if ace_paths[0] == "/" and ace_paths[1] == "/lib/": ace_inc = "$(ace_root)" ace_lib = "$(ace_root)/lib" if omni_paths[0] == "/bin/x86_win32/" and \ omni_paths[1] == "/include/" and \ omni_paths[2] == "/lib/x86_win32/" : omni_bin = "$(omni_root)/bin/x86_win32" omni_inc = "$(omni_root)/include" omni_lib = "$(omni_root)/lib/x86_win32" ace_root = re.sub("/", "\\\\", ace_root) omni_root = re.sub("/", "\\\\", omni_root) ace_inc = re.sub("/", "\\\\", ace_inc) ace_lib = re.sub("/", "\\\\", ace_lib) omni_bin = re.sub("/", "\\\\", omni_bin) omni_inc = re.sub("/", "\\\\", omni_inc) omni_lib = re.sub("/", "\\\\", omni_lib) fname = self.gen_entryw.get() if os.path.isdir(fname): tkMessageBox.showerror(title=self.isdir_error, message=self.isdir_error + fname) return if os.path.isfile(fname): if not tkMessageBox.askyesno(title=self.file_exists, message=self.file_exists + fname): return f = open(fname, "w") f.write(prop_sheet % \ (ace_root, omni_root, \ ace_inc, ace_lib, \ omni_inc, omni_lib, omni_bin)) f.close() tkMessageBox.showinfo(title=self.file_gened, message=self.file_gened + fname) return def search(self): w = { "ACE.h" : ["ace_inc", "ace/ACE.h"], "ACE.lib" : ["ace_lib", "ACE.lib"], "omniidl.exe" : ["omni_bin", "omniidl.exe"], "omniORB.h" : ["omni_inc", "omniORB4/omniORB.h"], "omniORB[0-9]+_rt.lib": ["omni_lib", "omniORB[0-9]+_rt.lib"] } res = {} dirname = self.search_dirw.get() if os.path.isdir(dirname): # th = thread.start_new_thread(search, (dirname, w.keys(), res)) search(dirname, w.keys(), res) else: tkMessageBox.showerror(title=self.dirname_error, message=self.dirname_error + dirname) return # 検索結果をEntryにセット for f in w.keys(): if res.has_key(f): l = len(self.ent[w[f][0]]["wid"].get()) self.ent[w[f][0]]["wid"].delete(0, l) t = re.sub(re.compile(w[f][1]), "", res[f]) self.ent[w[f][0]]["wid"].insert(0, t) # 検索結果を取得 ace_dirs = [ self.ent["ace_inc"]["wid"].get(), self.ent["ace_lib"]["wid"].get() ] omni_dirs = [ self.ent["omni_bin"]["wid"].get(), self.ent["omni_inc"]["wid"].get(), self.ent["omni_lib"]["wid"].get() ] # 共通パスを取得 ace_root = "" if ace_dirs[0] != "" or ace_dirs[1] != "": ace_root, ace_paths = self.common_path(ace_dirs) omni_root = "" if omni_dirs[0] != "" or \ omni_dirs[1] != "" or \ omni_dirs[2] != "": omni_root, omni_paths = self.common_path(omni_dirs) if omni_root != "": l = len(self.ent["omni_root"]["wid"].get()) self.ent["omni_root"]["wid"].delete(0, l) self.ent["omni_root"]["wid"].insert(0, omni_root) # ACE_ROOT, OMNI_ROOTをEntryにセット if ace_root != "": l = len(self.ent["ace_root"]["wid"].get()) self.ent["ace_root"]["wid"].delete(0, l) self.ent["ace_root"]["wid"].insert(0, ace_root) return def common_path_len(self, plist): for i in range(len(plist[0])): # ディレクトリ名を比較 dirname = plist[0][i] for j in range(1, len(plist)): if dirname != plist[j][i]: return i return def common_path_split(self, paths): plist = [] for p in paths: plist.append(p.split("/")) return plist def common_path(self, paths): plist = self.common_path_split(paths) comlen = self.common_path_len(plist) compath="" for i in range(comlen): compath += plist[0][i] if i != comlen - 1: compath += "/" diff_paths = [""] * len(paths) for i in range(len(paths)): diff_paths[i] = "" for j in range(comlen, len(plist[i])): diff_paths[i] += "/" + plist[i][j] return compath, diff_paths def __init__(self, master=None): Frame.__init__(self, master) self.pack(); self.init() if __name__ == "__main__": app = App(); app.mainloop() # end. "
21 win_title = "OpenRTM-aist-win32 Build Environment Setting"
22 
23 jexplain = """OpenRTM-aistをビルドするために必要な環境を設定します。下記の項目に必要な情報を入力して、プロパティシート生成ボタンを押してください。"""
24 
25 explain = """Setting up OpenRTM-aist build environment. Please input information to the following forms, and push Generate button to generate property sheet"""
26 
27 jsearch_expln = """自動的に検索することもできます。検索するディレクトリを入力して「検索」ボタンを押してください。
28 検索には数分かかることがあります。"""
29 search_expln = """Automatic search. Input search directory and push [Search] button.
30 It may take a few minutes."""
31 
32 jsearch_dir = "検索ディレクトリ"
33 search_dir = "Search Directory"
34 
35 jsbutton="検索 sbutton="Search" jdirname_error="ディレクトリが見つかりません。" dirname_error="DIrectory not found." entries = { "ace_root" : \ {"label": "ACE directory", "expln": "The ACE_wrapper directory a.k.a ACE_ROOT directory."}, "ace_inc" : \ {"label": "ACE include directory", "expln": "The directory in which ace/ACE.h exists."}, "ace_lib" : \ {"label": "ACE lib directory", "expln": "The directory in which ACE.LIB exists."}, "omni_root": \ {"label": "omniORB directory", "expln": "The omniORB directory in which bin, include, lib dirs exist."}, "omni_bin" : \ {"label": "omniORB bin directory", "expln": "The directory in which omniidl exists."}, "omni_inc" : \ {"label": "omniORB include directory", "expln": "The directory in which omniORB4/CORBA.h exists"}, "omni_lib" : \ {"label": "omniORB lib directory", "expln": "The directory in wihch omniORB407_rt.lib exists."} } jentries = { "ace_root" : \ {"label": "ACEディレクトリ", "expln": "通常はACE_wrapperディレクトリの位置を指定してください。"}, "ace_inc" : \ {"label": "ACE include ディレクトリ", "expln": "ace/ACE.hがあるディレクトリを指定してください。"}, "ace_lib" : \ {"label": "ACE lib ディレクトリ", "expln": "ACE.LIBがある場所を指定してください。"}, "omni_root": \ {"label": "omniORBディレクトリ", "expln": "omniORBのディレクトリ(下にbin, include, libがある)を指定してください。"}, "omni_bin" : \ {"label": "omniORB bin ディレクトリ", "expln": "omniidlがあるディレクトリを指定してください。"}, "omni_inc" : \ {"label": "omniORB include ディレクトリ", "expln": "omniORB4/CORBA.hがあるディレクトリを指定してください。"}, "omni_lib" : \ {"label": "omniORB lib ディレクトリ", "expln": "omniORB407_rt.libなどがあるディレクトリを指定してください。"} } jgbutton="生成" gbutton="Generate" jgen_label="プロパティシート:" gen_label="Property Sheet:" jgen_expln = """OpenRTM-aistソースディレクトリの下にOpenRTM-aist.vspropsというファイル名でプロパティシートを生成する必要があります。ACEやomniORBの各種パスおよびプロパティシートのディレクトリが正しければ生成ボタンを押してください。""" 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.""" prop_sheet = """<?xml version="1.0" encoding="shift_jis"?> <VisualStudioPropertySheet ProjectType="Visual C++" Version="8.00" Name="OpenRTM-aist-0.4" > <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\\rtm\idl&quot;;&quot;$(ace_include)&quot;;&quot;$(omni_include)&quot;;.;..\..;..;..\..\.." /> <Tool Name="VCLinkerTool" AdditionalLibraryDirectories="&quot;$(SolutionDir)\\bin&quot;;&quot;$(ace_libdir)&quot;;&quot;$(omni_libdir)&quot;" /> <UserMacro Name="ace_root" Value="%s" /> <UserMacro Name="omni_root" Value="%s" /> <UserMacro Name="rtm_root" Value="$(SolutionDir)" /> <UserMacro Name="ace_include" Value="%s" /> <UserMacro Name="ace_libdir" Value="%s" /> <UserMacro Name="omni_include" Value="%s" /> <UserMacro Name="omni_libdir" Value="%s" /> <UserMacro Name="omni_bin" Value="%s" /> <UserMacro Name="rtm_includes" Value="$(SolutionDir);$(SolutionDir)\\rtm\idl;$(ace_include);$(omni_include);.;..\..\\" /> <UserMacro Name="rtm_libdir" Value="$(SolutionDir)\\bin;$(ace_libdir);$(omni_libdir);." /> <UserMacro Name="rtm_path" Value="$(SolutionDir)\\bin;$(SolutionDir)\\build;&quot;$(omni_bin)&quot;" /> </VisualStudioPropertySheet> """ jisdir_error = "同名のディレクトリが存在します。 " isdir_error = "The Directory of a same name exists. " jfile_exists = "ファイルが存在します。上書きしますか? " file_exists = "The file already exists. Overwrite? " jfile_gened = "ファイルを生成しました。" file_gened = "File generated." def search(path, fnames, results): try: flist = os.listdir(path) except: return mp = [] for fn in fnames: mp.append(re.compile(fn)) for f in flist: fullpath = path + "/" + f if os.path.isfile(fullpath): # for fname in fnames: # if f == fname: # results[fname] = fullpath i = 0 for m in mp: if m.match(f): results[fnames[i]] = fullpath i += 1 elif os.path.isdir(fullpath): res = search(fullpath, fnames, results) return def j(str, encoding="cp932"): return unicode(str, encoding).encode("utf8") class App(Frame): def init(self): self.setlang() self.width=512 self.f8 = Font(weight=NORMAL, family="", size=8) self.f9 = Font(weight=NORMAL, family="", size=9) self.f10 = Font(weight=NORMAL, family="", size=10) self.f11 = Font(weight=NORMAL, family="", size=11) self.master.title(self.win_title) f = Frame() # 説明 self.expw = Label(f, text=self.explain, font=self.f11, \ justify=LEFT, wraplength=self.width) self.expw.pack(side=TOP, anchor=W, padx=3, pady=3) self.search_frame(f) self.entries_frame(f) self.gen_frame(f) f.pack(side=TOP, anchor=E, pady=5) def setlang(self): if time.tzname[0].find("東京") or time.tzname[0].find("JST"): self.ent = jentries self.win_title = j(jwin_title) self.explain = j(jexplain) self.search_expln = j(jsearch_expln) self.search_dir = j(jsearch_dir) self.search_button = j(jsbutton) self.gen_button = j(jgbutton) self.dirname_error=j(jdirname_error) self.gen_label = j(jgen_label) self.gen_expln = j(jgen_expln) self.isdir_error = j(jisdir_error) self.file_exists = j(jfile_exists) self.file_gened = j(jfile_gened) else: self.ent = entries self.win_title = win_title self.explain = explain self.search_expln = search_expln self.search_dir = search_dir self.search_button = sbutton self.gen_button = gbutton self.dirname_error=dirname_error self.gen_label = gen_label self.gen_expln = gen_expln self.isdir_error = isdir_error self.file_exists = file_exists self.file_gened = file_gened def search_frame(self, f): frame = Frame(f, relief=Tkinter.GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) # 自動検索の説明 self.search_explnw = Label(frame, text=self.search_expln, \ wraplength=self.width, justify=LEFT,\ font=self.f11) self.search_explnw.pack(side=TOP, anchor=W, padx=0) f1 = Frame(frame, width=self.width) f1.pack(side=TOP) self.search_labelw = Label(f1, text=self.search_dir, font=self.f11) self.search_labelw.pack(side=LEFT, anchor=W) self.search_dirw = Entry(f1, width=40, font=self.f11) self.search_dirw.delete(0) self.search_dirw.insert(0, default_searchdir) self.search_dirw.pack(side=LEFT, anchor=W, padx=5, pady=5) self.search_button = Button(f1, text=self.search_button, command=self.search, font=self.f10) self.search_button.pack(side=LEFT, anchor=W, padx=10, pady=5) f1.pack(side=TOP, anchor=W) def entries_frame(self, f): frame = Frame(f, relief=GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) for w in widlist: self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["label"]), \ font=self.f11, wraplength='10c') self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10) self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["expln"]), \ font=self.f9, wraplength='10c') self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10) self.ent[w]["wid"] = Entry(frame, width=80, font=self.f9) self.ent[w]["wid"].pack(side=TOP, anchor=NW, padx=10, pady=5) def gen_frame(self, f): frame = Frame(f, relief=Tkinter.GROOVE, bd=2) dummyw = Frame(frame, width=self.width) dummyw.pack(side=TOP) frame.pack(side=TOP) self.gen_expw = Label(frame, text=self.gen_expln, \ wraplength=self.width, justify=LEFT,\ font=self.f11) self.gen_expw.pack(side=TOP, anchor=W, padx=0) f1 = Frame(frame) self.gen_labelw = Label(f1, text=self.gen_label, font=self.f11) self.gen_labelw.pack(side=LEFT, anchor=W, padx=3, pady=3) self.gen_entryw = Entry(f1, width=40, \ text="OpenRTM-aist.vsprops", font=self.f11) self.gen_entryw.insert(0, property_sheet) self.gen_entryw.pack(side=LEFT, anchor=W, padx=5, pady=5) self.gbuttonw = Button(f1, text=self.gen_button, font=self.f10, command=self.generate) self.gbuttonw.pack(side=LEFT, anchor=W, padx=3, pady=3) f1.pack(side=TOP, anchor=W) def quit(self): self.master.destroy() def generate(self): ace_inc = self.ent["ace_inc"]["wid"].get() ace_lib = self.ent["ace_lib"]["wid"].get() ace_dirs = [ace_inc, ace_lib] omni_bin = self.ent["omni_bin"]["wid"].get() omni_inc = self.ent["omni_inc"]["wid"].get() omni_lib = self.ent["omni_lib"]["wid"].get() omni_dirs = [omni_bin, omni_inc, omni_lib] ace_root, ace_paths = self.common_path(ace_dirs) omni_root, omni_paths = self.common_path(omni_dirs) print ace_paths print ace_root print ace_inc if ace_paths[0] == "/" and ace_paths[1] == "/lib/": ace_inc = "$(ace_root)" ace_lib = "$(ace_root)/lib" if omni_paths[0] == "/bin/x86_win32/" and \ omni_paths[1] == "/include/" and \ omni_paths[2] == "/lib/x86_win32/" : omni_bin = "$(omni_root)/bin/x86_win32" omni_inc = "$(omni_root)/include" omni_lib = "$(omni_root)/lib/x86_win32" ace_root = re.sub("/", "\\\\", ace_root) omni_root = re.sub("/", "\\\\", omni_root) ace_inc = re.sub("/", "\\\\", ace_inc) ace_lib = re.sub("/", "\\\\", ace_lib) omni_bin = re.sub("/", "\\\\", omni_bin) omni_inc = re.sub("/", "\\\\", omni_inc) omni_lib = re.sub("/", "\\\\", omni_lib) fname = self.gen_entryw.get() if os.path.isdir(fname): tkMessageBox.showerror(title=self.isdir_error, message=self.isdir_error + fname) return if os.path.isfile(fname): if not tkMessageBox.askyesno(title=self.file_exists, message=self.file_exists + fname): return f = open(fname, "w") f.write(prop_sheet % \ (ace_root, omni_root, \ ace_inc, ace_lib, \ omni_inc, omni_lib, omni_bin)) f.close() tkMessageBox.showinfo(title=self.file_gened, message=self.file_gened + fname) return def search(self): w = { "ACE.h" : ["ace_inc", "ace/ACE.h"], "ACE.lib" : ["ace_lib", "ACE.lib"], "omniidl.exe" : ["omni_bin", "omniidl.exe"], "omniORB.h" : ["omni_inc", "omniORB4/omniORB.h"], "omniORB[0-9]+_rt.lib": ["omni_lib", "omniORB[0-9]+_rt.lib"] } res = {} dirname = self.search_dirw.get() if os.path.isdir(dirname): # th = thread.start_new_thread(search, (dirname, w.keys(), res)) search(dirname, w.keys(), res) else: tkMessageBox.showerror(title=self.dirname_error, message=self.dirname_error + dirname) return # 検索結果をEntryにセット for f in w.keys(): if res.has_key(f): l = len(self.ent[w[f][0]]["wid"].get()) self.ent[w[f][0]]["wid"].delete(0, l) t = re.sub(re.compile(w[f][1]), "", res[f]) self.ent[w[f][0]]["wid"].insert(0, t) # 検索結果を取得 ace_dirs = [ self.ent["ace_inc"]["wid"].get(), self.ent["ace_lib"]["wid"].get() ] omni_dirs = [ self.ent["omni_bin"]["wid"].get(), self.ent["omni_inc"]["wid"].get(), self.ent["omni_lib"]["wid"].get() ] # 共通パスを取得 ace_root = "" if ace_dirs[0] != "" or ace_dirs[1] != "": ace_root, ace_paths = self.common_path(ace_dirs) omni_root = "" if omni_dirs[0] != "" or \ omni_dirs[1] != "" or \ omni_dirs[2] != "": omni_root, omni_paths = self.common_path(omni_dirs) if omni_root != "": l = len(self.ent["omni_root"]["wid"].get()) self.ent["omni_root"]["wid"].delete(0, l) self.ent["omni_root"]["wid"].insert(0, omni_root) # ACE_ROOT, OMNI_ROOTをEntryにセット if ace_root != "": l = len(self.ent["ace_root"]["wid"].get()) self.ent["ace_root"]["wid"].delete(0, l) self.ent["ace_root"]["wid"].insert(0, ace_root) return def common_path_len(self, plist): for i in range(len(plist[0])): # ディレクトリ名を比較 dirname = plist[0][i] for j in range(1, len(plist)): if dirname != plist[j][i]: return i return def common_path_split(self, paths): plist = [] for p in paths: plist.append(p.split("/")) return plist def common_path(self, paths): plist = self.common_path_split(paths) comlen = self.common_path_len(plist) compath="" for i in range(comlen): compath += plist[0][i] if i != comlen - 1: compath += "/" diff_paths = [""] * len(paths) for i in range(len(paths)): diff_paths[i] = "" for j in range(comlen, len(plist[i])): diff_paths[i] += "/" + plist[i][j] return compath, diff_paths def __init__(self, master=None): Frame.__init__(self, master) self.pack(); self.init() if __name__ == "__main__": app = App(); app.mainloop() # end. "
36 sbutton="Search"
37 
38 jdirname_error="ディレクトリが見つかりません。"
39 dirname_error="DIrectory not found."
40 
41 
42 entries = {
43  "ace_root" : \
44  {"label": "ACE directory",
45  "expln": "The ACE_wrapper directory a.k.a ACE_ROOT directory."},
46  "ace_inc" : \
47  {"label": "ACE include directory",
48  "expln": "The directory in which ace/ACE.h exists."},
49  "ace_lib" : \
50  {"label": "ACE lib directory",
51  "expln": "The directory in which ACE.LIB exists."},
52  "omni_root": \
53  {"label": "omniORB directory",
54  "expln": "The omniORB directory in which bin, include, lib dirs exist."},
55  "omni_bin" : \
56  {"label": "omniORB bin directory",
57  "expln": "The directory in which omniidl exists."},
58  "omni_inc" : \
59  {"label": "omniORB include directory",
60  "expln": "The directory in which omniORB4/CORBA.h exists"},
61  "omni_lib" : \
62  {"label": "omniORB lib directory",
63  "expln": "The directory in wihch omniORB407_rt.lib exists."}
64  }
65 
66 jentries = {
67  "ace_root" : \
68  {"label": "ACEディレクトリ",
69  "expln": "通常はACE_wrapperディレクトリの位置を指定してください。"},
70  "ace_inc" : \
71  {"label": "ACE include ディレクトリ",
72  "expln": "ace/ACE.hがあるディレクトリを指定してください。"},
73  "ace_lib" : \
74  {"label": "ACE lib ディレクトリ",
75  "expln": "ACE.LIBがある場所を指定してください。"},
76  "omni_root": \
77  {"label": "omniORBディレクトリ",
78  "expln": "omniORBのディレクトリ(下にbin, include, libがある)を指定してください。"},
79  "omni_bin" : \
80  {"label": "omniORB bin ディレクトリ",
81  "expln": "omniidlがあるディレクトリを指定してください。"},
82  "omni_inc" : \
83  {"label": "omniORB include ディレクトリ",
84  "expln": "omniORB4/CORBA.hがあるディレクトリを指定してください。"},
85  "omni_lib" : \
86  {"label": "omniORB lib ディレクトリ",
87  "expln": "omniORB407_rt.libなどがあるディレクトリを指定してください。"}
88  }
89 
90 
91 jgbutton="生成"
92 gbutton="Generate"
93 
94 jgen_label="プロパティシート:"
95 gen_label="Property Sheet:"
96 
97 jgen_expln = """OpenRTM-aistソースディレクトリの下にOpenRTM-aist.vspropsというファイル名でプロパティシートを生成する必要があります。ACEやomniORBの各種パスおよびプロパティシートのディレクトリが正しければ生成ボタンを押してください。"""
98 
99 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."""
100 
101 prop_sheet = """<?xml version="1.0" encoding="shift_jis"?>
102 <VisualStudioPropertySheet
103  ProjectType="Visual C++"
104  Version="8.00"
105  Name="OpenRTM-aist-0.4"
106  >
107  <Tool
108  Name="VCCLCompilerTool"
109  AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\\rtm\idl&quot;;&quot;$(ace_include)&quot;;&quot;$(omni_include)&quot;;.;..\..;..;..\..\.."
110  />
111  <Tool
112  Name="VCLinkerTool"
113  AdditionalLibraryDirectories="&quot;$(SolutionDir)\\bin&quot;;&quot;$(ace_libdir)&quot;;&quot;$(omni_libdir)&quot;"
114  />
115  <UserMacro
116  Name="ace_root"
117  Value="%s"
118  />
119  <UserMacro
120  Name="omni_root"
121  Value="%s"
122  />
123  <UserMacro
124  Name="rtm_root"
125  Value="$(SolutionDir)"
126  />
127  <UserMacro
128  Name="ace_include"
129  Value="%s"
130  />
131  <UserMacro
132  Name="ace_libdir"
133  Value="%s"
134  />
135  <UserMacro
136  Name="omni_include"
137  Value="%s"
138  />
139  <UserMacro
140  Name="omni_libdir"
141  Value="%s"
142  />
143  <UserMacro
144  Name="omni_bin"
145  Value="%s"
146  />
147  <UserMacro
148  Name="rtm_includes"
149  Value="$(SolutionDir);$(SolutionDir)\\rtm\idl;$(ace_include);$(omni_include);.;..\..\\"
150  />
151  <UserMacro
152  Name="rtm_libdir"
153  Value="$(SolutionDir)\\bin;$(ace_libdir);$(omni_libdir);."
154  />
155  <UserMacro
156  Name="rtm_path"
157  Value="$(SolutionDir)\\bin;$(SolutionDir)\\build;&quot;$(omni_bin)&quot;"
158  />
159 </VisualStudioPropertySheet>
160 """
161 
162 jisdir_error = "同名のディレクトリが存在します。 "
163 isdir_error = "The Directory of a same name exists. "
164 
165 jfile_exists = "ファイルが存在します。上書きしますか? "
166 file_exists = "The file already exists. Overwrite? "
167 
168 jfile_gened = "ファイルを生成しました。"
169 file_gened = "File generated."
170 
171 
172 def search(path, fnames, results):
173  try:
174  flist = os.listdir(path)
175  except:
176  return
177 
178  mp = []
179  for fn in fnames:
180  mp.append(re.compile(fn))
181 
182  for f in flist:
183  fullpath = path + "/" + f
184  if os.path.isfile(fullpath):
185 # for fname in fnames:
186 # if f == fname:
187 # results[fname] = fullpath
188  i = 0
189  for m in mp:
190  if m.match(f):
191  results[fnames[i]] = fullpath
192  i += 1
193  elif os.path.isdir(fullpath):
194  res = search(fullpath, fnames, results)
195  return
196 
197 
198 def j(str, encoding="cp932"):
199  return unicode(str, encoding).encode("utf8")
200 
201 
202 
203 class App(Frame):
204  def init(self):
205  self.setlang()
206  self.width=512
207 
208  self.f8 = Font(weight=NORMAL, family="", size=8)
209  self.f9 = Font(weight=NORMAL, family="", size=9)
210  self.f10 = Font(weight=NORMAL, family="", size=10)
211  self.f11 = Font(weight=NORMAL, family="", size=11)
212 
213  self.master.title(self.win_title)
214 
215  f = Frame()
216 
217  # 説明
218  self.expw = Label(f, text=self.explain, font=self.f11, \
219  justify=LEFT, wraplength=self.width)
220  self.expw.pack(side=TOP, anchor=W, padx=3, pady=3)
221 
222  self.search_frame(f)
223  self.entries_frame(f)
224  self.gen_frame(f)
225  f.pack(side=TOP, anchor=E, pady=5)
226 
227  def setlang(self):
228  if time.tzname[0].find("東京") or time.tzname[0].find("JST"):
229  self.ent = jentries
230  self.win_title = j(jwin_title)
231  self.explain = j(jexplain)
232  self.search_expln = j(jsearch_expln)
233  self.search_dir = j(jsearch_dir)
234  self.search_button = j(jsbutton)
235  self.gen_button = j(jgbutton)
236  self.dirname_error=j(jdirname_error)
237  self.gen_label = j(jgen_label)
238  self.gen_expln = j(jgen_expln)
239  self.isdir_error = j(jisdir_error)
240  self.file_exists = j(jfile_exists)
241  self.file_gened = j(jfile_gened)
242  else:
243  self.ent = entries
244  self.win_title = win_title
245  self.explain = explain
246  self.search_expln = search_expln
247  self.search_dir = search_dir
248  self.search_button = sbutton
249  self.gen_button = gbutton
250  self.dirname_error=dirname_error
251  self.gen_label = gen_label
252  self.gen_expln = gen_expln
253  self.isdir_error = isdir_error
254  self.file_exists = file_exists
255  self.file_gened = file_gened
256 
257  def search_frame(self, f):
258  frame = Frame(f, relief=Tkinter.GROOVE, bd=2)
259  dummyw = Frame(frame, width=self.width)
260  dummyw.pack(side=TOP)
261  frame.pack(side=TOP)
262  # 自動検索の説明
263  self.search_explnw = Label(frame, text=self.search_expln, \
264  wraplength=self.width, justify=LEFT,\
265  font=self.f11)
266  self.search_explnw.pack(side=TOP, anchor=W, padx=0)
267 
268  f1 = Frame(frame, width=self.width)
269  f1.pack(side=TOP)
270 
271  self.search_labelw = Label(f1, text=self.search_dir, font=self.f11)
272  self.search_labelw.pack(side=LEFT, anchor=W)
273  self.search_dirw = Entry(f1, width=40, font=self.f11)
274  self.search_dirw.delete(0)
275  self.search_dirw.insert(0, default_searchdir)
276  self.search_dirw.pack(side=LEFT, anchor=W, padx=5, pady=5)
277  self.search_button = Button(f1, text=self.search_button,
278  command=self.search, font=self.f10)
279  self.search_button.pack(side=LEFT, anchor=W, padx=10, pady=5)
280  f1.pack(side=TOP, anchor=W)
281 
282  def entries_frame(self, f):
283  frame = Frame(f, relief=GROOVE, bd=2)
284  dummyw = Frame(frame, width=self.width)
285  dummyw.pack(side=TOP)
286  frame.pack(side=TOP)
287  for w in widlist:
288  self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["label"]), \
289  font=self.f11, wraplength='10c')
290  self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10)
291  self.ent[w]["wid"] = Label(frame, text=j(self.ent[w]["expln"]), \
292  font=self.f9, wraplength='10c')
293  self.ent[w]["wid"].pack(side=TOP, anchor=W, padx=10)
294  self.ent[w]["wid"] = Entry(frame, width=80, font=self.f9)
295  self.ent[w]["wid"].pack(side=TOP, anchor=NW, padx=10, pady=5)
296 
297  def gen_frame(self, f):
298  frame = Frame(f, relief=Tkinter.GROOVE, bd=2)
299  dummyw = Frame(frame, width=self.width)
300  dummyw.pack(side=TOP)
301  frame.pack(side=TOP)
302 
303  self.gen_expw = Label(frame, text=self.gen_expln, \
304  wraplength=self.width, justify=LEFT,\
305  font=self.f11)
306  self.gen_expw.pack(side=TOP, anchor=W, padx=0)
307 
308  f1 = Frame(frame)
309  self.gen_labelw = Label(f1, text=self.gen_label, font=self.f11)
310  self.gen_labelw.pack(side=LEFT, anchor=W, padx=3, pady=3)
311  self.gen_entryw = Entry(f1, width=40, \
312  text="OpenRTM-aist.vsprops", font=self.f11)
313  self.gen_entryw.insert(0, property_sheet)
314  self.gen_entryw.pack(side=LEFT, anchor=W, padx=5, pady=5)
315  self.gbuttonw = Button(f1, text=self.gen_button, font=self.f10,
316  command=self.generate)
317  self.gbuttonw.pack(side=LEFT, anchor=W, padx=3, pady=3)
318  f1.pack(side=TOP, anchor=W)
319 
320 
321  def quit(self):
322  self.master.destroy()
323 
324  def generate(self):
325  ace_inc = self.ent["ace_inc"]["wid"].get()
326  ace_lib = self.ent["ace_lib"]["wid"].get()
327  ace_dirs = [ace_inc, ace_lib]
328 
329  omni_bin = self.ent["omni_bin"]["wid"].get()
330  omni_inc = self.ent["omni_inc"]["wid"].get()
331  omni_lib = self.ent["omni_lib"]["wid"].get()
332  omni_dirs = [omni_bin, omni_inc, omni_lib]
333 
334  ace_root, ace_paths = self.common_path(ace_dirs)
335  omni_root, omni_paths = self.common_path(omni_dirs)
336 
337  print ace_paths
338  print ace_root
339  print ace_inc
340  if ace_paths[0] == "/" and ace_paths[1] == "/lib/":
341  ace_inc = "$(ace_root)"
342  ace_lib = "$(ace_root)/lib"
343 
344  if omni_paths[0] == "/bin/x86_win32/" and \
345  omni_paths[1] == "/include/" and \
346  omni_paths[2] == "/lib/x86_win32/" :
347  omni_bin = "$(omni_root)/bin/x86_win32"
348  omni_inc = "$(omni_root)/include"
349  omni_lib = "$(omni_root)/lib/x86_win32"
350 
351  ace_root = re.sub("/", "\\\\", ace_root)
352  omni_root = re.sub("/", "\\\\", omni_root)
353  ace_inc = re.sub("/", "\\\\", ace_inc)
354  ace_lib = re.sub("/", "\\\\", ace_lib)
355  omni_bin = re.sub("/", "\\\\", omni_bin)
356  omni_inc = re.sub("/", "\\\\", omni_inc)
357  omni_lib = re.sub("/", "\\\\", omni_lib)
358 
359  fname = self.gen_entryw.get()
360 
361  if os.path.isdir(fname):
362  tkMessageBox.showerror(title=self.isdir_error,
363  message=self.isdir_error + fname)
364  return
365 
366  if os.path.isfile(fname):
367  if not tkMessageBox.askyesno(title=self.file_exists,
368  message=self.file_exists + fname):
369  return
370 
371  f = open(fname, "w")
372  f.write(prop_sheet % \
373  (ace_root, omni_root, \
374  ace_inc, ace_lib, \
375  omni_inc, omni_lib, omni_bin))
376  f.close()
377  tkMessageBox.showinfo(title=self.file_gened,
378  message=self.file_gened + fname)
379  return
380 
381  def search(self):
382  w = {
383  "ACE.h" : ["ace_inc", "ace/ACE.h"],
384  "ACE.lib" : ["ace_lib", "ACE.lib"],
385  "omniidl.exe" : ["omni_bin", "omniidl.exe"],
386  "omniORB.h" : ["omni_inc", "omniORB4/omniORB.h"],
387  "omniORB[0-9]+_rt.lib": ["omni_lib", "omniORB[0-9]+_rt.lib"]
388  }
389  res = {}
390  dirname = self.search_dirw.get()
391  if os.path.isdir(dirname):
392 # th = thread.start_new_thread(search, (dirname, w.keys(), res))
393  search(dirname, w.keys(), res)
394  else:
395  tkMessageBox.showerror(title=self.dirname_error,
396  message=self.dirname_error + dirname)
397  return
398 
399  # 検索結果をEntryにセット
400  for f in w.keys():
401  if res.has_key(f):
402  l = len(self.ent[w[f][0]]["wid"].get())
403  self.ent[w[f][0]]["wid"].delete(0, l)
404  t = re.sub(re.compile(w[f][1]), "", res[f])
405  self.ent[w[f][0]]["wid"].insert(0, t)
406 
407  # 検索結果を取得
408  ace_dirs = [
409  self.ent["ace_inc"]["wid"].get(),
410  self.ent["ace_lib"]["wid"].get()
411  ]
412 
413  omni_dirs = [
414  self.ent["omni_bin"]["wid"].get(),
415  self.ent["omni_inc"]["wid"].get(),
416  self.ent["omni_lib"]["wid"].get()
417  ]
418 
419  # 共通パスを取得
420  ace_root = ""
421  if ace_dirs[0] != "" or ace_dirs[1] != "":
422  ace_root, ace_paths = self.common_path(ace_dirs)
423 
424  omni_root = ""
425  if omni_dirs[0] != "" or \
426  omni_dirs[1] != "" or \
427  omni_dirs[2] != "":
428  omni_root, omni_paths = self.common_path(omni_dirs)
429 
430 
431  if omni_root != "":
432  l = len(self.ent["omni_root"]["wid"].get())
433  self.ent["omni_root"]["wid"].delete(0, l)
434  self.ent["omni_root"]["wid"].insert(0, omni_root)
435 
436  # ACE_ROOT, OMNI_ROOTをEntryにセット
437  if ace_root != "":
438  l = len(self.ent["ace_root"]["wid"].get())
439  self.ent["ace_root"]["wid"].delete(0, l)
440  self.ent["ace_root"]["wid"].insert(0, ace_root)
441 
442  return
443 
444 
445  def common_path_len(self, plist):
446  for i in range(len(plist[0])): # ディレクトリ名を比較
447  dirname = plist[0][i]
448  for j in range(1, len(plist)):
449  if dirname != plist[j][i]:
450  return i
451  return
452 
453  def common_path_split(self, paths):
454  plist = []
455  for p in paths:
456  plist.append(p.split("/"))
457  return plist
458 
459  def common_path(self, paths):
460  plist = self.common_path_split(paths)
461  comlen = self.common_path_len(plist)
462 
463  compath=""
464  for i in range(comlen):
465  compath += plist[0][i]
466  if i != comlen - 1:
467  compath += "/"
468 
469  diff_paths = [""] * len(paths)
470  for i in range(len(paths)):
471  diff_paths[i] = ""
472  for j in range(comlen, len(plist[i])):
473  diff_paths[i] += "/" + plist[i][j]
474 
475  return compath, diff_paths
476 
477 
478 
479  def __init__(self, master=None):
480  Frame.__init__(self, master)
481  self.pack(); self.init()
482 
483 
484 if __name__ == "__main__": app = App(); app.mainloop()
485 # end.
486 
def quit(self)
Definition: RunAtFirst.py:321
def setlang(self)
Definition: RunAtFirst.py:227
def common_path_len(self, plist)
Definition: RunAtFirst.py:445
def entries_frame(self, f)
Definition: RunAtFirst.py:282
def search_frame(self, f)
Definition: RunAtFirst.py:257
def search(path, fnames, results)
Definition: RunAtFirst.py:172
void insert(CorbaSequence &seq, SequenceElement &elem, CORBA::ULong index)
Insert the element to the CORBA sequence.
def j(str, encoding="cp932")
Definition: RunAtFirst.py:198
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
def search(self)
Definition: RunAtFirst.py:381
def gen_frame(self, f)
Definition: RunAtFirst.py:297
def common_path(self, paths)
Definition: RunAtFirst.py:459
def generate(self)
Definition: RunAtFirst.py:324
def common_path_split(self, paths)
Definition: RunAtFirst.py:453
def __init__(self, master=None)
Definition: RunAtFirst.py:479
def init(self)
Definition: RunAtFirst.py:204


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00