1 # -*- coding: utf-8 -*-
3 from __future__
import absolute_import
5 import urllib2
, sys
, os
, random
6 from jben
.preferences
import Preferences
8 # The following is shamelessly copied from:
9 # http://ftp.monash.edu.au/pub/nihongo/.message
10 #old_static_mirror_list = [
11 # "http://ftp.monash.edu.au/pub/nihongo", # Original FTP archive
12 # "http://japanology.arts.kuleuven.ac.be/mirrors/monash", # Belgium
13 # "ftp://ftp.nrc.ca/pub/packages/nihongo", # Canada (fast site)
14 # "http://www.bcit-broadcast.com/monash", # Canada (http only)
15 # "ftp://ftp.sedl.org/pub/mirrors/nihongo", # US(Texas)
16 # "ftp://ftp.net.usf.edu/pub/monash", # IS (Florida)
17 # "ftp://ftp.u-aizu.ac.jp/pub/SciEng/nihongo/ftp.cc.monash.edu.au", # Japan
18 # "ftp://ftp.funet.fi/pub/culture/japan/mirrors/monash", # Finland
19 # "ftp://ftp.uni-duisburg.de/Mirrors/ftp.monash.edu.au/pub/nihongo" # Germany
22 # Based upon checking the mirrors myself, this is the list I'll use
24 static_mirror_list
= [
26 # (redirects to ringtail.its.monash.edu.au/pub/nihongo, same IP address)
27 "http://ftp.monash.edu.au/pub/nihongo",
29 "ftp://ftp.nrc.ca/pub/packages/nihongo", # Canada (fast site)
30 "ftp://ftp.net.usf.edu/pub/monash/pub/nihongo", # IS (Florida)
31 "ftp://ftp.uni-duisburg.de/Mirrors/ftp.monash.edu.au/pub/nihongo", # Germany
32 # *Probably* up to date (but can't tell since I can't see file mtimes)
33 "http://japanology.arts.kuleuven.ac.be/mirrors/monash", # Belgium
34 "http://www.bcit-broadcast.com/monash", # Canada (http only)
36 #"ftp://ftp.u-aizu.ac.jp/pub/SciEng/nihongo/ftp.cc.monash.edu.au", # Japan
37 #"ftp://ftp.funet.fi/pub/culture/japan/mirrors/monash", # Finland
39 #"ftp://ftp.sedl.org/pub/mirrors/nihongo", # US(Texas) - "not available"
42 def get_mirror_list(from_inet
=False,
43 mirror
="http://ftp.monash.edu.au/pub/nihongo"):
44 """Grabs a mirror list from a valid mirror of Jim Breen's FTP archive."""
46 # NOTE: although this function does what it says, the mirror list
47 # is not dependable for our purposes. Not all mirrors are up to
48 # date, and one mirror appears to be down. I advise not using
49 # from_inet for the time being.
53 f
= urllib2
.urlopen("%s/%s" % (mirror
, ".message"))
55 mirrors
= ["http://ftp.monash.edu.au/pub/nihongo"]
58 line
= line
[1:].strip().replace("\t", " ")
59 l
= [s
.strip() for s
in line
.split(" ", 1)]
64 except urllib2
.URLError
, e
:
65 print >> sys
.stderr
, e
70 return static_mirror_list
72 def download_dict(fname
):
73 mirrors
= get_mirror_list(from_inet
=False)
74 dpath
= p
.get_dict_path()
75 print "Using output dict path:", dpath
77 def get_next_mirror():
78 i
= random
.randrange(0, len(mirrors
))
81 mirror
= get_next_mirror()
84 url
= "%s/%s" % (mirror
, fname
)
85 target_fname
= "%s/%s" % (dpath
, fname
)
87 print "Downloading %s to %s..." % (url
, target_fname
)
88 resp
= urllib2
.urlopen(url
)
91 if not os
.path
.exists(dpath
):
93 ofile
= open(target_fname
, "wb")
98 print >> sys
.stderr
, \
99 "An error occurred; trying the next mirror."
100 print >> sys
.stderr
, "(%s)" % str(e
)
101 mirror
= get_next_mirror()
107 print "The following dictionaries are available:"
108 dicts
= [("edict.gz", "EDICT"),
109 #("edict2.gz", "EDICT2"),
110 ("JMdict.gz", "JMdict (full)"),
111 ("JMdict_e.gz", "JMdict_e (English only)"),
112 ("kanjidic.gz", "KANJIDIC"),
113 #("kanjd212.gz", "KANJD212"),
114 ("kanjidic2.xml.gz", "KANJIDIC2")]
115 for i
, (fname
, desc
) in enumerate(dicts
):
116 print "\t%d: %s" % (i
+1, desc
)
117 sys
.stdout
.write("Enter the numbers for the dictionaries you want, "
118 "separated by spaces: ")
119 s
= sys
.stdin
.readline()
125 if i
not in range(len(dicts
)):
126 print >> sys
.stderr
, "Value %s is out of range." % s
128 except ValueError, e
:
129 print >> sys
.stderr
, "Ignoring invalid value %s" % d
137 if __name__
== "__main__":