OSDN Git Service

d1f6da93b8f4f9b05f4dda34149f0389fdabc8ac
[rec10/rec10-git.git] / rec10 / install.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 import time
6 import os.path
7 import ConfigParser
8 import sys
9 import commands
10 import configwriter
11 import shutil
12 import traceback
13
14 import recdblist
15 def printutf8(str):
16     print str.encode('utf-8')
17 def install():
18     version = recdblist.version
19     recdblist.printutf8(u"rec10の環境インストールを開始します。",verbose_level=100)
20     time.sleep(1)
21     recdblist.printutf8(u"環境インストール処理中・・・",verbose_level=100)
22     path = str(os.path.dirname(os.path.abspath(__file__)))
23     confp = ConfigParser.SafeConfigParser()
24     Conf = 'rec10.conf'
25     confpath=""
26     if os.path.exists(os.path.join(path,Conf)):
27         confpath=os.path.join(path,Conf)
28     elif os.path.exists(os.path.join("/etc","rec10.conf")):
29         confpath=os.path.join("/etc","rec10.conf")
30     elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")):
31         confpath=os.path.join("/etc/rec10","rec10.conf")
32     if confpath!="":
33         confp.read(confpath)
34     else:
35         recdblist.printutf8(u"rec10.confが見つかりません。",verbose_level=100)
36         recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。",verbose_level=100)
37         sys.exit(1)
38     recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath,verbose_level=100)
39     if confp.get('path',"recpath")=="/path of /recording":
40         recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)",verbose_level=100)
41         sys.exit(1)
42     recdblist.printutf8(u"DB処理に入ります",verbose_level=100)
43     if os.path.exists(os.path.join(path,"rec10d.py")):
44         try:
45             update_db_all()
46         except Exception, inst:
47             recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。",verbose_level=100)
48             recdblist.printutf8(str(type(inst)),verbose_level=100)
49             recdblist.printutf8(str(inst)+"\n"+traceback.format_exc(),verbose_level=100)
50     import rec10d
51     rec10d.rec10db.change_installed_in_status()
52     recdblist.printutf8(u"チャンネル設定に入ります",verbose_level=100)
53     import scan_ch
54     rec10d.rec10db.new_epg_ch()
55     recdblist.printutf8(u"チャンネルスキャンの開始",verbose_level=100)
56     scan_ch.searchCh()
57     rec10d.rec10db.change_installed_in_status(100)
58     recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100)
59     recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100)
60     sys.exit(1)
61 def getLocalPath(cmd,exit=1):
62     printutf8(cmd+u"の場所を確認中")
63     txt=commands.getoutput(u"which "+cmd)
64     if len(txt.split(" "))>3:
65         if exit==1:
66             printutf8(cmd+u"の場所を確認できませんでした。終了します")
67             sys.exit(1)
68         else:
69             return ""
70     else:
71         printutf8(cmd+u" : "+txt)
72         if len(txt.splitlines()):
73             txt=txt.splitlines()[0]
74         return txt.strip()
75 def move():
76     useB=0
77     path = str(os.path.dirname(os.path.abspath(__file__)))
78     printutf8(u"rec10 ver "+recdblist.version_str+" installer.")
79     printutf8(u"rec10のインストールを開始します。")
80     maxn=16
81     configwriter.setTempConfPath(u"wine", getLocalPath(u"wine"))
82     configwriter.setTempConfPath(u"recpt1", getLocalPath(u"recpt1",exit=0))
83     #configwriter.setpath(u"x264", getLocalPath(u"x264"))
84     configwriter.setTempConfPath(u"mp4box", getLocalPath(u"MP4Box",exit=0))
85     configwriter.setTempConfPath(u"mencoder", getLocalPath(u"mencoder"))
86     configwriter.setTempConfPath(u"ffmpeg", getLocalPath(u"ffmpeg"))
87     configwriter.setTempConfPath(u"mkvmerge", getLocalPath(u"mkvmerge",exit=0))
88     configwriter.setTempConfPath(u"lame", getLocalPath(u"lame",exit=0))
89     configwriter.setTempConfPath(u"b25", getLocalPath(u"b25"))
90     configwriter.setTempConfPath(u"tee", getLocalPath(u"tee"))
91     configwriter.setTempConfPath(u"java", getLocalPath(u"java"))
92
93     try:
94         configwriter.setTempConfPath(u"lame", getLocalPath(u"lame"))
95     except:
96         printutf8(u"lameが見つかりません(NeroAacEncを導入する場合は問題ありません)")
97     printutf8(u"必須環境の設定が完了しました")
98     printutf8(u"個人設定に入ります")
99     if os.path.exists("/etc/rec10.conf"):
100         printutf8(u"以前の設定ファイルが見つかりました。")
101         printutf8(u"インポートしますか?")
102         useB=raw_input("[Y/n]:")
103         if useB=="N" or useB == "n":
104             useB=0
105         else:
106             useB=1
107             printutf8(u"設定ファイルのインポートを行います。")
108     printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")")
109     printutf8(u"100GB程度は確保されている必要があります")
110     recpath=getConf(useB,"/etc/rec10.conf","path","recpath","path : ")
111     configwriter.setTempConfPath(u"recpath",recpath)
112     printutf8(u"DBの設定に入ります。")
113     printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")")
114     mysql_user=getConf(useB,"/etc/rec10.conf","db","mysql_user","mysql_user : ")
115     configwriter.setTempConfDB("mysql_user", mysql_user)
116     printutf8(u"パスワードを設定してください(3/"+str(maxn)+")")
117     mysql_passwd=getConf(useB,"/etc/rec10.conf","db","mysql_passwd","mysql_passwd : ")
118     configwriter.setTempConfDB("mysql_passwd", mysql_passwd)
119     printutf8(u"BS/CSの設定に入ります")
120     printutf8(u"BS/CS(110度CS,スカパーe2)を受信しますか(4/"+str(maxn)+")")
121     useBSCS=raw_input("[Y/n]:")
122     if useBSCS=="N" or useBSCS=="n" or useBSCS=="no" or useBSCS=="NO":
123         useBSCS="0"
124     else:
125         useBSCS="1"
126     printutf8(u"ドライバの設定に入ります")
127     printutf8(u"DVB版のドライバを使用しますか(earth_pt1など。chardev版を使う場合はNo)(5/"+str(maxn)+")")
128     useDVB=raw_input("[y/N]:")
129     if useDVB=="Y" or useDVB=="y" or useDVB=="yes" or useDVB=="YES":
130         useDVB="1"
131     else:
132         useDVB="0"
133     configwriter.setTempConfDVB("useDVB", useDVB)
134     if useDVB=="1":
135         printutf8(u"DVBの設定に入ります")
136         printutf8(u"DVBAdapterの場所を設定して下さい")
137         printutf8(u"/dev/dvb/adapterなどdvr0の上のフォルダ(番号の前まで)を指定して下さい。")
138         getConf(useB,"/etc/rec10.conf","dvb","DVBadapter","/dev/dvb/adapter")
139         printutf8(u"地デジを受信可能なアダプタ番号を入力して下さい(1,3のように','で区切って下さい)")
140         getConf(useB,"/etc/rec10.conf","dvb","DVBTE","1,3")
141         if useBSCS=="1":
142             printutf8(u"BS/CSを受信可能なアダプタ番号を入力して下さい(0,2のように','で区切って下さい)")
143             getConf(useB,"/etc/rec10.conf","dvb","DVBBSCS","0,2")
144         else:
145             configwriter.setTempConfDVB("DVBBSCS","")
146     printutf8(u"同時録画可能数の設定に入ります")
147     printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(6/"+str(maxn)+")")
148     te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : ")))
149     configwriter.setTempConfEnv("te_max", te_max)
150     if useBSCS=="1":
151         printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(7/"+str(maxn)+")")
152         bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : ")))
153         configwriter.setTempConfEnv("bscs_max", bscs_max)
154     else:
155         configwriter.setTempConfEnv("bscs_max", "0")
156     printutf8(u"同時エンコード最大数を設定してください(8/"+str(maxn)+")")
157     printutf8(u"CPUのコア数が目安です")
158     enc_max=raw_input("[2]:")
159     if enc_max=="":
160         enc_max="2"
161     else:
162         enc_max=str(int(enc_max))
163     configwriter.setTempConfEnv("enc_max", enc_max)
164     printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))")
165     printutf8(u"入手先:http://www.nero.com/jpn/technologies-aac-codec.html\n (9/"+str(maxn)+")")
166     audioenc=raw_input("[y/N]:  ")
167     if audioenc=="y" or audioenc=="Y":
168         configwriter.setTempConfPath("useNeroAAC", "1")
169         aacpath=getLocalPath(u"neroAacEnc",exit=0)
170         if len(aacpath)<2:
171             printutf8(u"NeroAACEncのパスを指定してください")
172             aacpath=getConf(useB,"/etc/rec10.conf","path","NeroAAC","[/usr/local/bin/neroAacEnc] : ")
173         if aacpath.replace(" ","")=="":
174             aacpath="/usr/local/bin/neroAacEnc"
175         configwriter.setTempConfPath("NeroAAC",aacpath)
176     else:
177         configwriter.setTempConfPath("useNeroAAC", "0")
178         aacpath="/usr/local/bin/neroAacEnc"
179         configwriter.setTempConfPath("NeroAAC",aacpath)
180         printutf8(u"lameを使用します。")
181     printutf8(u"x264のパスを指定してください(10/"+str(maxn)+")")
182     x264path=getConf(useB,"/etc/rec10.conf","path","x264","x264 path : ")
183     if x264path.replace(" ","")=="" or not os.path.isfile(x264path):
184         x264path=getLocalPath(u"x264")
185     configwriter.setTempConfPath("x264",x264path)
186     printutf8(u"保存する画質を教えてください(11/"+str(maxn)+")")
187     printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります")
188     crf=getConf(useB,"/etc/rec10.conf","env","crf","[24] : ")
189     if crf.replace(" ","")=="":
190         crf="24"
191     configwriter.setTempConfEnv("crf", crf)
192     printutf8(u"アニメーションを保存する画質を教えてください(12/"+str(maxn)+")")
193     printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります")
194     a_crf=getConf(useB,"/etc/rec10.conf","env","animation_crf","[20] : ")
195     if a_crf.replace(" ","")=="":
196         a_crf="20"
197     configwriter.setTempConfEnv("animation_crf", a_crf)
198     printutf8(u"x264の圧縮率を設定してください(13/"+str(maxn)+")")
199     printutf8(u"x264のpresetの値です。標準だとmedium、小さければ小さいほど高圧縮になります")
200     preset=getConf(useB,"/etc/rec10.conf","env","x264_preset","[4] : ")
201     if preset.replace(" ","")=="":
202         preset="4"
203     configwriter.setTempConfEnv("x264_preset", preset)
204     printutf8(u"保存するコンテナの設定(14/"+str(maxn)+")")
205     printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)")
206     useMP4=raw_input("[Y/n]:")
207     if useMP4=="N" or useMP4 == "n" :
208         useMP4="0"
209     else:
210         useMP4="1"
211     configwriter.setTempConfEnv("make_mp4", useMP4)
212     printutf8(u"TSファイルの自動削除(15/"+str(maxn)+")")
213     printutf8(u"中間体のtsファイルを削除しますか")
214     printutf8(u"(削除するとやり直しができないため残しておくことを推奨します。)")
215     removeTS=raw_input("[y/N]:")
216     if removeTS=="Y" or removeTS == "y" :
217         removeTS="1"
218     else:
219         removeTS="0"
220     configwriter.setTempConfEnv("remove_ts", removeTS)
221     printutf8(u"自機識別オプション(16/"+str(maxn)+")")
222     printutf8(u"本rec10の識別名を入力してください")
223     printutf8(u"複数台のrec10を運用する場合に効果的です。空白でもかまいません。")
224     printutf8(u"例 kobe01")
225     iff=getConf(useB,"/etc/rec10.conf","env","iff","[] : ")
226     configwriter.setTempConfEnv("iff", iff)
227     confp = ConfigParser.SafeConfigParser()
228     confp.read("/etc/rec10.conf")
229     if useB:
230         configwriter.setTempConfPath("recorded",confp.get("path","recorded"))
231         configwriter.setTempConfPath("move_destpath",confp.get("path","move_destpath"))
232         configwriter.setTempConfPath("tmp",confp.get("path","tmp"))
233         try:
234             configwriter.setTempConfEnv("x264_addline",confp.get("env","x264_addline"))
235         except:
236             configwriter.setTempConfEnv("x264_addline","")
237         if confp.get("path","b25_remote")=="":
238             configwriter.setTempConfPath("b25_remote", "0")
239         elif confp.get("path","b25_remote")=="1":
240             configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote"))
241             configwriter.setTempConfPath("b25", confp.get("path","b25"))
242             configwriter.setTempConfPath("b25_env", confp.get("path","b25_env"))
243         else:
244             configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote"))
245
246     configwriter.writeTempConf()
247     printutf8(u"初期設定が終了しました。")
248     printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。")
249 def getConf(useBeforeConf,Confpath,dbsection,key,defaultstr):
250     tstr=defaultstr
251     if os.path.exists(Confpath) and useBeforeConf==1:
252         try:
253             confp = ConfigParser.SafeConfigParser()
254             confp.read("/etc/rec10.conf")
255             tstr=u"["+confp.get(dbsection,key)+u"]:"
256         except:
257             tstr=defaultstr
258     tmpconf=raw_input(tstr)
259     if tmpconf.replace(" ","")=="" and os.path.exists(Confpath) and useBeforeConf==1 :
260         confp = ConfigParser.SafeConfigParser()
261         confp.read("/etc/rec10.conf")
262         try:
263             tmpconf=confp.get(dbsection,key)
264         except:
265             tmpconf=""
266     return tmpconf
267 def update_db_all():
268     import rec10d
269     tversion=0
270     if rec10d.rec10db.select_installed_in_status()==1:
271         if rec10d.rec10db.select_version_in_status()==0:
272             tversion=0
273             recdblist.printutf8(u"既存のDBが見つかりました。0.9.1と仮定してアップデート処理を行います。",verbose_level=100)
274             update_db(0)
275             time.sleep(1)
276         else:
277             recdblist.printutf8(u"既存のDBが見つかりました。アップデート処理を行います。",verbose_level=100)
278         tversion=int(rec10d.rec10db.select_version_in_status())
279         while (recdblist.version>tversion):
280             update_db(tversion)
281             tversion=int(rec10d.rec10db.select_version_in_status())
282     else:
283         rec10d.rec10db.drop_in_status()
284         rec10d.rec10db.drop_in_settings()
285         time.sleep(2)
286         rec10d.rec10db.new_in_status()
287         rec10d.rec10db.new_in_settings()
288         rec10d.rec10db.change_version_in_status(recdblist.version)
289 def update_db(version):
290     import rec10d
291     if version==0:
292         rec10d.rec10db.update_db_to93()
293     elif version==93:
294         rec10d.rec10db.update_db_93to94()
295     elif version==94:
296         rec10d.rec10db.update_db_94to95()
297     elif version==95:
298         rec10d.rec10db.update_db_95to96()
299     elif version==96:
300         rec10d.rec10db.update_db_96to98()
301     elif version==98:
302         rec10d.re/Users/matsuohidetoshi/Desktop/git/rec10-git/rec10/install.shc10db.update_db_98to100()
303     elif version==100:
304         rec10d.rec10db.update_db_100to101()
305     elif version==101:
306         rec10d.rec10db.update_db_100to102()
307 if __name__ == "__main__":
308     move()