Class: MythTv

Inherits:
SphinxModule show all
Defined in:
lib/modules/mythtv.rb

Instance Method Summary collapse

Methods inherited from SphinxModule

#load_configuration, #save_configuration, #setup, #uninstall, #update

Constructor Details

#initializeMythTv

Returns a new instance of MythTv.



5
6
7
8
9
10
# File 'lib/modules/mythtv.rb', line 5

def initialize
  @config = {
      :version => SphinxTv::VERSION
  }
  load_configuration
end

Instance Method Details

#check(quiet = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/modules/mythtv.rb', line 12

def check(quiet = false)
  result = true
  result = false unless mythtv_backend_installed?(quiet)
  result = false unless mythtv_frontend_installed?(quiet)
  unless @config[:database_password]
    result = false
    puts "Assuming no database is set up as the MythTV database password is not set.'".red unless quiet
  end
  unless File.exists? "/usr/local/bin/mythfilldatabase"
    result = false
    puts "No symbolic link to mythfilldatabase found".red unless quiet
  end

  puts "MythTV is OK.".green if result
  result
end

#configureObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/modules/mythtv.rb', line 29

def configure
  exit = false
  until exit do
    choose do |menu|
      menu.header = "\nMythTV Configuration".cyan
      menu.prompt = "Select an option: "
      if mythtv_backend_installed?
        menu.choice("Setup database") { setup_database }
      end
      menu.choice("Create Storage Directories") { create_storage_directories }
      if mythtv_backend_running?
        menu.choice("MythTV Backend Control " + "Loaded".green) { mythtv_backend_control(false) }
      else
        menu.choice("MythTV Backend Control " + "Unloaded".red) { mythtv_backend_control(true) }
      end
      menu.choice("Done") {
        exit = true
      }
    end
  end
end

#downloadObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/modules/mythtv.rb', line 51

def download
  doc = Nokogiri::HTML(open('http://sourceforge.net/projects/mythtvformacosx/files/'))

  doc.css('tr.file  a').each do |link|
    if /\.dmg\/download$/.match(link[:href])
      filename = nil
      if /MythBack.*10\.7/.match(link[:href])
        filename = "MythBackend.dmg"
      elsif /MythFront.*10\.7/.match(link[:href])
        filename = "MythFrontend.dmg"
      end
      if filename
        puts "Downloading #{filename}".cyan
        puts link[:href]
        Download::url(link[:href], SphinxTv::download_path(filename))
      end
    end
  end
end

#installObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/modules/mythtv.rb', line 71

def install
  puts "Installing MythTV".cyan
  unless check(true)
    download
    install_mythtv_backend unless mythtv_backend_installed?
    install_mythtv_frontend unless mythtv_frontend_installed?

    unless File.exists? "/usr/local/bin/mythfilldatabase"
      puts "Creating link to mythfilldatabase".cyan
      %x[sudo #{SphinxTv::SUDO_PROMPT} mkdir -p /usr/local/bin]
      %x[sudo #{SphinxTv::SUDO_PROMPT} ln -s /Applications/MythBackend.app/Contents/MacOS/mythfilldatabase /usr/local/bin/mythfilldatabase]
    end
  end
end