OSDN Git Service

fix installer.
[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             time.sleep(2)
44             rec10d.rec10db.new_in_status()
45         except Exception, inst:
46             recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。")
47             print type(inst)
48             print inst
49     recdblist.printutf8(u"チャンネル設定に入ります")
50     if os.path.exists(os.path.join(path,"chlist.xml")):
51         recdblist.printutf8(u"チャンネルリストが見つかりました。||chlist.xml")
52     else:
53         recdblist.printutf8(u"チャンネルリストが見つかりません。"+os.path.join(path,"chlist.xml")+u"を作成してください。")
54         recdblist.printutf8(u"東京/名古屋/神戸のサンプルがchlist_sample_*.xmlにあるため、参考にしてください。")
55         sys.exit(1)
56     recdblist.printutf8(u"BS放送は受信可能ですか?")
57     bsok=raw_input("y/N:")
58     if bsok=="Y" or bsok == "y" :
59         bsok=1
60     else:
61         bsok=0
62     recdblist.printutf8(u"CS放送は受信可能ですか?")
63     csok=raw_input("y/N:")
64     if csok=="Y" or csok == "y" :
65         csok=1
66     else:
67         csok=0
68     import chdata
69     chdata.new_chdata(bsok,csok)
70     recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。")
71     recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)")
72     import rec10d
73     rec10d.rec10db.change_installed_in_status()
74     time.sleep(10)
75     import timerec
76     timerec.task()
77 def getpath(cmd):
78     recdblist.printutf8(cmd+u"の場所を確認中")
79     txt=commands.getoutput(u"which "+cmd)
80     if len(txt.splitlines())>2:
81         recdblist.printutf8(cmd+u"の場所を確認できませんでした。終了します")
82         sys.exit(1)
83     else:
84         recdblist.printutf8(cmd+u" : "+txt)
85         return txt.strip()
86 def move():
87     path = str(os.path.dirname(os.path.abspath(__file__)))
88     recdblist.printutf8(u"rec10 ver 0.9.1 installer.")
89     recdblist.printutf8(u"rec10のインストールを開始します。")
90     
91     configwriter.setpath(u"wine", getpath(u"wine"))
92     configwriter.setpath(u"recpt1", getpath(u"recpt1"))
93     configwriter.setpath(u"xvfb-run", getpath(u"xvfb-run"))
94     configwriter.setpath(u"mkvmerge", getpath(u"mkvmerge"))
95     configwriter.setpath(u"b25", getpath(u"b25"))
96     recdblist.printutf8(u"必須環境の設定が完了しました")
97     recdblist.printutf8(u"個人設定に入ります")
98     recdblist.printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/)")
99     recdblist.printutf8(u"100GB程度は確保されている必要があります")
100     recpath=raw_input("path : ")
101     configwriter.setpath(u"recpath",recpath)
102     recdblist.printutf8(u"DBの設定に入ります。")
103     recdblist.printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/)")
104     mysql_user=raw_input("mysql_user : ")
105     configwriter.setdbpath("mysql_user", mysql_user)
106     recdblist.printutf8(u"パスワードを設定してください(3/)")
107     mysql_passwd=raw_input("mysql_passwd : ")
108     configwriter.setdbpath("mysql_passwd", mysql_passwd)
109     recdblist.printutf8(u"同時録画可能数の設定に入ります")
110     recdblist.printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(4/)")
111     te_max=raw_input("te_max : ")
112     te_max=str(int(te_max))
113     configwriter.setenv("te_max", te_max)
114     recdblist.printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(5/)")
115     bscs_max=raw_input("bscs_max : ")
116     bscs_max=str(int(bscs_max))
117     configwriter.setenv("bscs_max", bscs_max)
118     recdblist.printutf8(u"同時エンコード最大数を設定してください(6/)")
119     recdblist.printutf8(u"CPUのコア数が目安です")
120     enc_max=raw_input("[2]:")
121     if enc_max=="":
122         enc_max="2"
123     else:
124         enc_max=str(int(enc_max))
125     configwriter.setenv("enc_max", enc_max)
126     recdblist.printutf8(u"チャンネルの設定に入ります(7/)")
127     recdblist.printutf8(u"rec10を設置する地域を選んでください。")
128     recdblist.printutf8(u"1:東京 2:神戸 3:名古屋 4:その他")
129     ch=raw_input()
130     ch=int(ch)
131     if ch==1:
132         shutil.copy(os.path.join(path,"chlist_sample_tokyo.xml"),os.path.join(path,"chlist.xml"))
133     elif ch==2:
134         shutil.copy(os.path.join(path,"chlist_sample_kobe.xml"),os.path.join(path,"chlist.xml"))
135     elif ch==3:
136         shutil.copy(os.path.join(path,"chlist_sample_nagoya.xml"),os.path.join(path,"chlist.xml"))
137     elif ch==4:
138         recdblist.printutf8(u"チャンネルの設定が必要です。")
139         recdblist.printutf8(u"chlist_sample_*を参考にchlist.xmlを作成した後に次のステップに進んでください。")
140         time.sleep(5)
141     recdblist.printutf8(u"初期設定が終了しました。")
142     recdblist.printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。")
143 if __name__ == "__main__":
144     move()