public
Description: Simple to use TVDB (thetvdb.com) API in Python, and automatic TV episode namer
Homepage: http://dbr.lighthouseapp.com/projects/13342-tvdb_api/tickets
Clone URL: git://github.com/dbr/tvdb_api.git
tvdb_api / Rakefile
100644 113 lines (92 sloc) 2.86 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'fileutils'
 
task :default => [:clean]
 
task :clean do
  [".", "tests"].each do |cd|
    puts "Cleaning directory #{cd}"
    Dir.new(cd).each do |t|
      if t =~ /.*\.pyc$/
        puts "Removing #{File.join(cd, t)}"
        File.delete(File.join(cd, t))
      end
    end
  end
end
 
desc "Upversion files"
task :upversion do
  puts "Upversioning"
 
  Dir.glob("*.py").each do |filename|
    f = File.new(filename, File::RDWR)
    contents = f.read()
 
    contents.gsub!(/__version__ = ".+?"/){|m|
      cur_version = m.scan(/\d+\.\d+/)[0].to_f
      new_version = cur_version + 0.1
 
      puts "Current version: #{cur_version}"
      puts "New version: #{new_version}"
 
      new_line = "__version__ = \"#{new_version}\""
 
      puts "Old line: #{m}"
      puts "New line: #{new_line}"
 
      m = new_line
    }
 
    puts contents[0]
 
    f.truncate(0) # empty the existing file
    f.seek(0)
    f.write(contents.to_s) # write modified file
    f.close()
  end
end
 
desc "Upload current version to PyPi"
task :topypi => :test do
  cur_file = File.open("tvdb_api.py").read()
  tvdb_api_version = cur_file.scan(/__version__ = "(.*)"/)
  tvdb_api_version = tvdb_api_version[0][0].to_f
 
  cur_file = File.open("tvnamer.py").read()
  tvnamer_version = cur_file.scan(/__version__ = "(.*)"/)
  tvnamer_version = tvnamer_version[0][0].to_f
 
  puts "Build sdist and send tvdb_api v#{tvdb_api_version} and tvnamer v#{tvnamer_version} to PyPi?"
  if $stdin.gets.chomp == "y"
    puts "Sending source-dist (sdist) to PyPi"
 
    FileUtils.mv("setup_tvdb_api.py", "setup.py")
    if system("python setup.py sdist register upload")
      print "tvdb_api uploaded!"
    end
    FileUtils.mv("setup.py", "setup_tvdb_api.py")
 
    FileUtils.mv("setup_tvnamer.py", "setup.py")
    if system("python setup.py sdist register upload")
      puts "tvnamer uploaded!"
    end
    FileUtils.mv("setup.py", "setup_tvnamer.py")
  else
    puts "Cancelled"
  end
end
 
desc "Profile by running unittests"
task :profile do
  cd "tests"
  puts "Profiling.."
  `python -m cProfile -o prof_runtest.prof runtests.py`
  puts "Converting prof to dot"
  `python gprof2dot.py -o prof_runtest.dot -f pstats prof_runtest.prof`
  puts "Generating graph"
  `~/Applications/dev/graphviz.app/Contents/macOS/dot -Tpng -o profile.png prof_runtest.dot -Gbgcolor=black`
  puts "Cleanup"
  rm "prof_runtest.dot"
  rm "prof_runtest.prof"
end
 
task :test do
  puts "Nosetest'ing"
  if not system("nosetests -v")
    raise "Test failed!"
  end
 
  puts "Doctesting *.py"
  Dir.glob("*.py").each do |filename|
    puts "Doctesting #{filename}"
    puts "python", "-m", "doctest", filename
    if not system("python", "-m", "doctest", filename)
      raise "Failed doctest"
    end
  end
 
  puts "Doctesting readme.md"
  if not system("python", "-m", "doctest", "readme.md")
    raise "Doctest"
  end
end