aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-10 23:43:55 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-10 23:43:55 -0300
commit6c3ddbea65aa1af1f0e4ae0c5f56ba344b470c56 (patch)
tree1fc55235ea10d374541d8d06fefea8d309e50199 /g_octave
parentimplemented overlay_bootstrap to emerge (diff)
downloadg-octave-6c3ddbea65aa1af1f0e4ae0c5f56ba344b470c56.tar.gz
g-octave-6c3ddbea65aa1af1f0e4ae0c5f56ba344b470c56.tar.bz2
g-octave-6c3ddbea65aa1af1f0e4ae0c5f56ba344b470c56.zip
added g_octave/installed.py, to help with the storage of packages
currently installed
Diffstat (limited to 'g_octave')
-rw-r--r--g_octave/installed.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/g_octave/installed.py b/g_octave/installed.py
new file mode 100644
index 0000000..e749178
--- /dev/null
+++ b/g_octave/installed.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+"""
+ installed.py
+ ~~~~~~~~~~~~
+
+ This module implements a Python object with the register of g-octave
+ installed packages, something like the portage's world file.
+
+ :copyright: (c) 2010 by Rafael Goncalves Martins
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import json
+
+class Installed(object):
+
+ # this will not be changed by the config file, because the user will
+ # lost track of the installed packages if he touch in the location
+ # of this file without move it.
+ _file = '/var/cache/g-octave.json'
+
+ def _load_json(self):
+ content = {}
+ try:
+ with open(self._file) as fp:
+ content = json.load(fp)
+ except:
+ return {}
+ return content
+
+ def _dump_json(self, content):
+ try:
+ with open(self._file, 'w') as fp:
+ json.dump(content, fp)
+ except:
+ return False
+ return True
+
+ def do_install(self, package, version):
+ packages = self._load_json()
+ packages[package] = version
+ if not self._dump_json(packages):
+ raise RuntimeError('Failed to save JSON file.')
+
+ def is_installed(self, package):
+ packages = self._load_json()
+ return package in packages
+
+ def get_version(self, package):
+ packages = self._load_json()
+ return packages.get(package, None)