OSDN Git Service

change pp video filter(md to ac).
[rec10/rec10-git.git] / rec10 / trunk / src / install.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import time
6 import os.path
7 import ConfigParser
8 import sys
9 import commands
10 import configwriter
11 import shutil
12
13 import recdblist
14 def install():
15     recdblist.printutf8(u"rec10の環境インストールを開始します。")
16     time.sleep(1)
17     recdblist.printutf8(u"環境インストール処理中・・・")
18     path = str(os.path.dirname(os.path.abspath(__file__)))
19     confp = ConfigParser.SafeConfigParser()
20     Conf = 'rec10.conf'
21     confpath=""
22     if os.path.exists(os.path.join(path,Conf)):
23         confpath=os.path.join(path,Conf)
24     elif os.path.exists(os.path.join("/etc","rec10.conf")):
25         confpath=os.path.join("/etc","rec10.conf")
26     elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")):
27         confpath=os.path.join("/etc/rec10","rec10.conf")
28     if confpath!="":
29         confp.read(confpath)
30     else:
31         recdblist.printutf8(u"rec10.confが見つかりません。")
32         recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。")
33         sys.exit(1)
34     recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath)
35     if confp.get('path',"recpath")=="/path of /recording":
36         recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)")
37         sys.exit(1)
38     recdblist.printutf8(u"DB処理に入ります")
39     if os.path.exists(os.path.join(path,"rec10d.py")):
40         try:
41             import rec10d
42             rec10d.rec10db.drop_in_status()
43             rec10d.rec10db.drop_in_settings()
44             time.sleep(2)
45             rec10d.rec10db.new_in_status()
46             rec10d.rec10db.new_in_settings()
47         except Exception, inst:
48             recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。")
49             print type(inst)
50             print inst
51     recdblist.printutf8(u"チャンネル設定に入ります")
52     if os.path.exists(os.path.join(path,"chlist.xml")):
53         recdblist.printutf8(u"チャンネルリストが見つかりました。||chlist.xml")
54     else:
55         recdblist.printutf8(u"チャンネルリストが見つかりません。"+os.path.join(path,"chlist.xml")+u"を作成してください。")
56         recdblist.printutf8(u"東京/名古屋/神戸のサンプルがchlist_sample_*.xmlにあるため、参考にしてください。")
57         sys.exit(1)
58     bsok=int(confp.get('env',"bs"))
59     csok=int(confp.get('env',"cs"))
60     import chdata
61     chdata.new_chdata(bsok,csok)
62     recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。")
63     recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)")
64     import rec10d
65     rec10d.rec10db.change_installed_in_status()
66 def getpath(cmd):
67     recdblist.printutf8(cmd+u"の場所を確認中")
68     txt=commands.getoutput(u"which "+cmd)
69     if len(txt.split(" "))>3:
70         recdblist.printutf8(cmd+u"の場所を確認できませんでした。終了します")
71         sys.exit(1)
72     else:
73         recdblist.printutf8(cmd+u" : "+txt)
74         if len(txt.splitlines()):
75             txt=txt.splitlines()[0]
76         return txt.strip()
77 def move():
78     path = str(os.path.dirname(os.path.abspath(__file__)))
79     recdblist.printutf8(u"rec10 ver 0.9.1 installer.")
80     recdblist.printutf8(u"rec10のインストールを開始します。")
81     maxn=9
82     configwriter.setpath(u"wine", getpath(u"wine"))
83     configwriter.setpath(u"recpt1", getpath(u"recpt1"))
84     #configwriter.setpath(u"xvfb-run", getpath(u"xvfb-run"))
85     configwriter.setpath(u"mkvmerge", getpath(u"mkvmerge"))
86     configwriter.setpath(u"b25", getpath(u"b25"))
87     recdblist.printutf8(u"必須環境の設定が完了しました")
88     recdblist.printutf8(u"個人設定に入ります")
89     recdblist.printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")")
90     recdblist.printutf8(u"100GB程度は確保されている必要があります")
91     recpath=raw_input("path : ")
92     configwriter.setpath(u"recpath",recpath)
93     recdblist.printutf8(u"DBの設定に入ります。")
94     recdblist.printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")")
95     mysql_user=raw_input("mysql_user : ")
96     configwriter.setdbpath("mysql_user", mysql_user)
97     recdblist.printutf8(u"パスワードを設定してください(3/"+str(maxn)+")")
98     mysql_passwd=raw_input("mysql_passwd : ")
99     configwriter.setdbpath("mysql_passwd", mysql_passwd)
100     recdblist.printutf8(u"同時録画可能数の設定に入ります")
101     recdblist.printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(4/"+str(maxn)+")")
102     te_max=raw_input("te_max : ")
103     te_max=str(int(te_max))
104     configwriter.setenv("te_max", te_max)
105     recdblist.printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(5/"+str(maxn)+")")
106     bscs_max=raw_input("bscs_max : ")
107     bscs_max=str(int(bscs_max))
108     configwriter.setenv("bscs_max", bscs_max)
109     recdblist.printutf8(u"同時エンコード最大数を設定してください(6/"+str(maxn)+")")
110     recdblist.printutf8(u"CPUのコア数が目安です")
111     enc_max=raw_input("[2]:")
112     if enc_max=="":
113         enc_max="2"
114     else:
115         enc_max=str(int(enc_max))
116     configwriter.setenv("enc_max", enc_max)
117     
118     recdblist.printutf8(u"チャンネルの設定に入ります(7/"+str(maxn)+")")
119     recdblist.printutf8(u"rec10を設置する地域を選んでください。")
120     recdblist.printutf8(u"1:東京 2:神戸 3:名古屋 4:その他")
121     ch=raw_input()
122     ch=int(ch)
123     if ch==1:
124         shutil.copy(os.path.join(path,"chlist_sample_tokyo.xml"),os.path.join(path,"chlist.xml"))
125     elif ch==2:
126         shutil.copy(os.path.join(path,"chlist_sample_kobe.xml"),os.path.join(path,"chlist.xml"))
127     elif ch==3:
128         shutil.copy(os.path.join(path,"chlist_sample_nagoya.xml"),os.path.join(path,"chlist.xml"))
129     elif ch==4:
130         recdblist.printutf8(u"チャンネルの設定が必要です。")
131         recdblist.printutf8(u"chlist_sample_*を参考にchlist.xmlを作成した後に次のステップに進んでください。")
132         time.sleep(5)
133     recdblist.printutf8(u"BS放送は受信可能ですか?(8/"+str(maxn)+")")
134     bsok=raw_input("y/N:")
135     if bsok=="Y" or bsok == "y" :
136         bsok="1"
137     else:
138         bsok="0"
139     configwriter.setenv("bs", bsok)
140     recdblist.printutf8(u"CS放送(スカパーe2)は受信可能ですか?(9/"+str(maxn)+")")
141     csok=raw_input("y/N:")
142     if csok=="Y" or csok == "y" :
143         csok="1"
144         recdblist.printutf8(u"標準パックの番組は入力してありますがそれ以外は追加でchlist_cs.xmlに追加する必要があります。")
145     else:
146         csok="0"
147     configwriter.setenv("cs", csok)
148     configwriter.writeconf()
149     recdblist.printutf8(u"初期設定が終了しました。")
150     recdblist.printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。")
151 if __name__ == "__main__":
152     move()