aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-06-14 23:41:41 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-06-14 23:41:41 -0300
commit07260d3cf9e3a76f9a2219c6e3a713a21ec986fe (patch)
tree8df37ef78a3ef317e1b08f65c64f8f588ebbe7de /g_octave
parentAdded tag 0.2_rc1 for changeset 0f4b33c590de (diff)
downloadg-octave-07260d3cf9e3a76f9a2219c6e3a713a21ec986fe.tar.gz
g-octave-07260d3cf9e3a76f9a2219c6e3a713a21ec986fe.tar.bz2
g-octave-07260d3cf9e3a76f9a2219c6e3a713a21ec986fe.zip
initial import of stuff to deal with the SVN repo. Don't use it yethg diff
Diffstat (limited to 'g_octave')
-rw-r--r--g_octave/svn/__init__.py0
-rw-r--r--g_octave/svn/client.py95
-rw-r--r--g_octave/svn/revisions.py54
3 files changed, 149 insertions, 0 deletions
diff --git a/g_octave/svn/__init__.py b/g_octave/svn/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/g_octave/svn/__init__.py
diff --git a/g_octave/svn/client.py b/g_octave/svn/client.py
new file mode 100644
index 0000000..29f5e9a
--- /dev/null
+++ b/g_octave/svn/client.py
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+
+"""
+ client.py
+ ~~~~~~~~~
+
+ This module implements a interface between g-octave and the octave-forge
+ Subversion repository.
+
+ :copyright: (c) 2010 by Rafael Goncalves Martins
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+import pysvn
+import shutil
+import subprocess
+import sys
+import urllib2
+
+
+class SvnClient:
+
+ url = 'https://octave.svn.sourceforge.net/svnroot/octave/trunk/octave-forge/'
+ categories = ['main', 'extra', 'language', 'nonfree']
+ exclude = ['CONTENTS', 'INDEX', 'Makefile', 'base']
+
+ def __init__(self, verbose=False):
+ self._verbose = verbose
+ self._client = pysvn.Client()
+ self.packages = {}
+ for category in self.categories:
+ self.packages[category] = self._list_packages(category)
+
+ def _list_packages(self, category):
+ try:
+ if self._verbose:
+ print 'Listing packages from: ' + category
+ pkg_list = self._client.list(
+ self.url + '/' + category + '/',
+ depth = pysvn.depth.immediates
+ )
+ except pysvn.ClientError, err:
+ print >> sys.stderr, 'Error: ' + str(err)
+ tmp_list = []
+ for props, lock in pkg_list:
+ filename = props.repos_path.split('/')[-1]
+ if filename not in self.exclude and filename != category:
+ tmp_list.append(filename)
+ return tmp_list
+
+ def create_description_tree(self, dest, categories=['main', 'extra', 'language']):
+ for category in categories:
+ if category not in self.categories:
+ continue
+ for pkg in self.packages[category]:
+ current_dir = os.path.join(dest, category, pkg)
+ os.makedirs(current_dir)
+ try:
+ if self._verbose:
+ print 'Fetching DESCRIPTION from: %s/%s' % (category, pkg)
+ fp = urllib2.urlopen(
+ self.url + '/' + category + '/' + pkg + '/DESCRIPTION'
+ )
+ with open(os.path.join(current_dir, 'DESCRIPTION'), 'w') as fp_:
+ shutil.copyfileobj(fp, fp_)
+ except urllib2.URLError:
+ pass
+
+
+ def checkout_package(self, category, name, dest, stable=True):
+ if stable:
+ # get DESCRIPTION revision
+ try:
+ info = self._client.info2(
+ self.url + '/' + category + '/' + name + '/DESCRIPTION'
+ )
+ except pysvn.ClientError, err:
+ return False
+ revision = info[0][1].last_changed_rev
+ try:
+ self._client.checkout(
+ self.url + '/' + category + '/' + name + '/',
+ dest,
+ revision = stable and revision or \
+ pysvn.Revision(pysvn.opt_revision_kind.head)
+ )
+ except pysvn.ClientError, err:
+ return False
+ return True
+
+ def create_tarball(self, category, name):
+ tmpdir = '/tmp/tmp-' + name
+ self.checkout_package(category, name, tmpdir)
+ shutil.copytree(tmpdir, '/tmp/'+name)
diff --git a/g_octave/svn/revisions.py b/g_octave/svn/revisions.py
new file mode 100644
index 0000000..4f5e98d
--- /dev/null
+++ b/g_octave/svn/revisions.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+
+"""
+ revisions.py
+ ~~~~~~~~~~~~
+
+ This module implements a Python object with the revisions for each
+ package fetched from the octave-forge SVN.
+
+ :copyright: (c) 2010 by Rafael Goncalves Martins
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import json
+
+class Revisions(object):
+
+ def __init__(self, json_file):
+ self._file = json_file
+
+ def _load_json(self):
+ revisions = {}
+ try:
+ with open(self._file) as fp:
+ revisions = json.load(fp)
+ except:
+ return {}
+ return revisions
+
+ def _dump_json(self, revisions):
+ try:
+ with open(self._file, 'w') as fp:
+ json.dump(revisions, fp)
+ except:
+ return False
+ return True
+
+ def __getitem__(self, key):
+ revisions = self._load_json()
+ if key in revisions:
+ return revisions[key]
+ return None
+
+ def __setitem__(self, key, value):
+ revisions = self._load_json()
+ revisions[key] = value
+ if not self._dump_json(revisions):
+ raise RuntimeError('Failed to save JSON file.')
+
+if __name__ == '__main__':
+ a = Revisions('/tmp/file.json')
+ a['fuuuu'] = 1234
+ print a['fuuuu']
+