[ckan-changes] [okfn/ckan] 66b596: import clean
GitHub
noreply at github.com
Fri Apr 20 10:17:07 UTC 2012
Branch: refs/heads/master
Home: https://github.com/okfn/ckan
Commit: 66b596ce01b1613a9398bb25d6b266e4b4828b6e
https://github.com/okfn/ckan/commit/66b596ce01b1613a9398bb25d6b266e4b4828b6e
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/lib/base.py
Log Message:
-----------
import clean
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index da9d69f..075029c 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -22,7 +22,7 @@
import ckan.exceptions
import ckan
-from ckan import authz
+import ckan.authz as authz
from ckan.lib import i18n
import ckan.lib.helpers as h
from ckan.plugins import PluginImplementations, IGenshiStreamFilter
================================================================
Commit: 79e42821a2eddfaedb12e6d6a5376ae4a6354a70
https://github.com/okfn/ckan/commit/79e42821a2eddfaedb12e6d6a5376ae4a6354a70
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/lib/cli.py
Log Message:
-----------
import clean in lib/cli
diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py
index 5146aa9..6798cc4 100644
--- a/ckan/lib/cli.py
+++ b/ckan/lib/cli.py
@@ -84,7 +84,7 @@ class ManageDb(CkanCommand):
def command(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
import ckan.lib.search as search
cmd = self.args[0]
@@ -164,7 +164,7 @@ def _postgres_dump(self, filepath):
self._run_cmd(pg_dump_cmd)
def _postgres_load(self, filepath):
- from ckan import model
+ import ckan.model as model
assert not model.repo.are_tables_created(), "Tables already found. You need to 'db clean' before a load."
pg_cmd = self._get_psql_cmd() + ' -f %s' % filepath
self._run_cmd(pg_cmd)
@@ -194,7 +194,7 @@ def load(self, only_load=False):
pg_cmd = self._postgres_load(dump_path)
if not only_load:
print 'Upgrading DB'
- from ckan import model
+ import ckan.model as model
model.repo.upgrade_db()
print 'Rebuilding search index'
@@ -205,7 +205,7 @@ def load(self, only_load=False):
print 'Done'
def simple_dump_csv(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need csv file path'
return
@@ -215,7 +215,7 @@ def simple_dump_csv(self):
dumper.SimpleDumper().dump(dump_file, format='csv')
def simple_dump_json(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need json file path'
return
@@ -452,7 +452,7 @@ class Sysadmin(CkanCommand):
def command(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
cmd = self.args[0] if self.args else None
if cmd == None or cmd == 'list':
@@ -465,7 +465,7 @@ def command(self):
print 'Command %s not recognized' % cmd
def list(self):
- from ckan import model
+ import ckan.model as model
print 'Sysadmins:'
sysadmins = model.Session.query(model.SystemRole).filter_by(role=model.Role.ADMIN)
print 'count = %i' % sysadmins.count()
@@ -477,7 +477,7 @@ def list(self):
user_or_authgroup.id)
def add(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need name of the user to be made sysadmin.'
@@ -501,7 +501,7 @@ def add(self):
print 'Added %s as sysadmin' % username
def remove(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need name of the user to be made sysadmin.'
@@ -537,7 +537,7 @@ class UserCmd(CkanCommand):
def command(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
if not self.args:
self.list()
@@ -563,7 +563,7 @@ def get_user_str(self, user):
return user_str
def list(self):
- from ckan import model
+ import ckan.model as model
print 'Users:'
users = model.Session.query(model.User)
print 'count = %i' % users.count()
@@ -571,14 +571,14 @@ def list(self):
print self.get_user_str(user)
def show(self):
- from ckan import model
+ import ckan.model as model
username = self.args[0]
user = model.User.get(unicode(username))
print 'User: \n', user
def setpass(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need name of the user.'
@@ -593,7 +593,7 @@ def setpass(self):
print 'Done'
def search(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need user name query string.'
@@ -618,7 +618,7 @@ def password_prompt(cls):
return password1
def add(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need name of the user.'
@@ -671,7 +671,7 @@ def add(self):
print user
def remove(self):
- from ckan import model
+ import ckan.model as model
if len(self.args) < 2:
print 'Need name of the user.'
@@ -704,7 +704,7 @@ class DatasetCmd(CkanCommand):
def command(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
if not self.args:
print self.usage
@@ -722,7 +722,7 @@ def command(self):
self.show(self.args[0])
def list(self):
- from ckan import model
+ import ckan.model as model
print 'Datasets:'
datasets = model.Session.query(model.Package)
print 'count = %i' % datasets.count()
@@ -732,19 +732,19 @@ def list(self):
print '%s %s %s' % (dataset.id, dataset.name, state)
def _get_dataset(self, dataset_ref):
- from ckan import model
+ import ckan.model as model
dataset = model.Package.get(unicode(dataset_ref))
assert dataset, 'Could not find dataset matching reference: %r' % dataset_ref
return dataset
def show(self, dataset_ref):
- from ckan import model
import pprint
dataset = self._get_dataset(dataset_ref)
pprint.pprint(dataset.as_dict())
def delete(self, dataset_ref):
- from ckan import model, plugins
+ from ckan import plugins
+ import ckan.model as model
dataset = self._get_dataset(dataset_ref)
old_state = dataset.state
@@ -756,7 +756,8 @@ def delete(self, dataset_ref):
print '%s %s -> %s' % (dataset.name, old_state, dataset.state)
def purge(self, dataset_ref):
- from ckan import model, plugins
+ from ckan import plugins
+ import ckan.model as model
dataset = self._get_dataset(dataset_ref)
name = dataset.name
@@ -802,7 +803,7 @@ def run_(self):
def view(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
from kombu.transport.sqlalchemy.models import Message
q = model.Session.query(Message)
q_visible = q.filter_by(visible=True)
@@ -816,7 +817,7 @@ def view(self):
def clean(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
import pprint
tasks_initially = model.Session.execute("select * from kombu_message").rowcount
if not tasks_initially:
@@ -847,7 +848,7 @@ class Ratings(CkanCommand):
def command(self):
self._load_config()
- from ckan import model
+ import ckan.model as model
cmd = self.args[0]
if cmd == 'count':
@@ -860,14 +861,14 @@ def command(self):
print 'Command %s not recognized' % cmd
def count(self):
- from ckan import model
+ import ckan.model as model
q = model.Session.query(model.Rating)
print "%i ratings" % q.count()
q = q.filter(model.Rating.user_id == None)
print "of which %i are anonymous ratings" % q.count()
def clean(self, user_ratings=True):
- from ckan import model
+ import ckan.model as model
q = model.Session.query(model.Rating)
print "%i ratings" % q.count()
if not user_ratings:
================================================================
Commit: e3c3c004ff21fa3848d49251310a8a4b399ab496
https://github.com/okfn/ckan/commit/e3c3c004ff21fa3848d49251310a8a4b399ab496
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/plugins/__init__.py
Log Message:
-----------
avoid circular imports in plugins.toolkit
diff --git a/ckan/plugins/__init__.py b/ckan/plugins/__init__.py
index fcb6055..e11e909 100644
--- a/ckan/plugins/__init__.py
+++ b/ckan/plugins/__init__.py
@@ -1,3 +1,19 @@
from ckan.plugins.core import *
from ckan.plugins.interfaces import *
-import toolkit
+
+
+class _Toolkit(object):
+ ''' This object allows us to avoid circular imports while making
+ functions/objects available to plugins. '''
+
+ def __init__(self):
+ self.toolkit = None
+
+ def __getattr__(self, name):
+ if not self.toolkit:
+ import toolkit
+ self.toolkit = toolkit
+ return getattr(self.toolkit, name)
+
+toolkit = _Toolkit()
+del _Toolkit
================================================================
Compare: https://github.com/okfn/ckan/compare/cf12111...e3c3c00
More information about the ckan-changes
mailing list