8000 Svn2git by ddale · Pull Request #2 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Svn2git #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 commits merged into from
Feb 22, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update examples to use sample_data from github
  • Loading branch information
ddale committed Feb 21, 2011
commit efed80d829af8c862cd87d3438ef3b9932ad9602
2 changes: 1 addition & 1 deletion examples/misc/sample_data_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Grab mpl data from the ~/.matplotlib/sample_data cache if it exists, else
fetch it from svn and cache it
fetch it from github and cache it
"""
import matplotlib.cbook as cbook
import matplotlib.pyplot as plt
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/sample_data_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Demonstrate how get_sample_data works with svn revisions in the data.
Demonstrate how get_sample_data works with git revisions in the data.

svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data
git clone git@github.com/matplotlib/sample_data.git

and edit testdata.csv to add a new row. After committing the changes,
when you rerun this script you will get the updated data (and the new
svn version will be cached in ~/.matplotlib/sample_data)
git version will be cached in ~/.matplotlib/sample_data)
"""

import matplotlib.mlab as mlab
Expand Down
29 changes: 16 additions & 13 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,13 @@ def to_filehandle(fname, flag='rU', return_opened=False):
def is_scalar_or_string(val):
return is_string_like(val) or not iterable(val)

class ViewVCCachedServer(urllib2.BaseHandler):
class ViewVCCachedServer(urllib2.HTTPSHandler):
"""
Urllib2 handler that takes care of caching files.
The file cache.pck holds the directory of files that have been cached.
"""
def __init__(self, cache_dir, baseurl):
urllib2.HTTPSHandler.__init__(self)
self.cache_dir = cache_dir
self.baseurl = baseurl
self.read_cache()
Expand Down Expand Up @@ -544,7 +545,7 @@ def cache_file(self, url, data, headers):
# http_error_304 for handling 304 Not Modified responses
# http_response for postprocessing requests

def http_request(self, req):
def https_request(self, req):
"""
Make the request conditional if we have a cached file.
"""
Expand All @@ -555,20 +556,21 @@ def http_request(self, req):
req.add_header("If-Modified-Since", lastmod)
return req

def http_error_304(self, req, fp, code, msg, hdrs):
def https_error_304(self, req, fp, code, msg, hdrs):
"""
Read the file from the cache since the server has no newer version.
"""
url = req.get_full_url()
fn, _, _ = self.cache[url]
matplotlib.verbose.report('ViewVCCachedServer: reading data file from cache file "%s"'
%fn, 'debug')
matplotlib.verbose.report(
'ViewVCCachedServer: reading data file from cache file "%s"' %fn,
'debug')
file = open(fn, 'rb')
handle = urllib2.addinfourl(file, hdrs, url)
handle.code = 304
return handle

def http_response(self, req, response):
def https_response(self, req, response):
"""
Update the cache with the returned file.
"""
Expand All @@ -589,7 +591,7 @@ def http_response(self, req, response):
def get_sample_data(self, fname, asfileobj=True):
"""
Check the cachedirectory for a sample_data file. If it does
not exist, fetch it with urllib from the svn repo and
not exist, fetch it with urllib from the git repo and
store it in the cachedir.

If asfileobj is True, a file object will be returned. Else the
Expand Down Expand Up @@ -637,21 +639,21 @@ def get_sample_data(self, fname, asfileobj=True):
def get_sample_data(fname, asfileobj=True):
"""
Check the cachedirectory ~/.matplotlib/sample_data for a sample_data
file. If it does not exist, fetch it with urllib from the mpl svn repo
file. If it does not exist, fetch it with urllib from the mpl git repo

http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/
https://github.com/matplotlib/sample_data/raw/master

and store it in the cachedir.

If asfileobj is True, a file object will be returned. Else the
path to the file as a string will be returned

To add a datafile to this directory, you need to check out
sample_data from matplotlib svn::
sample_data from matplotlib git::

svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data
git clone git@github.com:matplotlib/sample_data

and svn add the data file you want to support. This is primarily
and git add the data file you want to support. This is primarily
intended for use in mpl examples that need custom data.

To bypass all downloading, set the rc parameter examples.download to False
Expand All @@ -670,12 +672,13 @@ def get_sample_data(fname, asfileobj=True):
if myserver is None:
configdir = matplotlib.get_configdir()
cachedir = os.path.join(configdir, 'sample_data')
baseurl = 'http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/'
baseurl = 'https://github.com/matplotlib/sample_data/raw/master/'
myserver = get_sample_data.myserver = ViewVCCachedServer(cachedir, baseurl)

return myserver.get_sample_data(fname, asfileobj=asfileobj)

get_sample_data.myserver = None

def flatten(seq, scalarp=is_scalar_or_string):
"""
this generator flattens nested containers such as
Expand Down
0