Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Commit

Permalink
[#23,ckan][m]: new ckan command to push data packages into ckan.
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Sep 10, 2014
1 parent 43e788e commit 9f79f48
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bin/dpm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var argv = optimist
' init <path> create a datapackage.json file in directory <path>',
' validate <path> validate datapackage.json file in directory <path>',
' install <url> install a data packages into the current project along with its dependencies',
' install <url> install a data packages into the current project along with its dependencies',
' ckan <url> push a data package into a ckan instance',
' help <command> Get help on command'
].join(os.EOL)
)
Expand Down Expand Up @@ -74,18 +76,20 @@ if (argv._[0] === 'init') {
if (err) _fail(err);
else console.log(tree.deps(dpkgs));
});
} else if(argv._[0] === 'ckan'){
dpm.ckan(argv, function(err, msg) {
if (err) _fail(err);
else console.log(msg);
});
} else if (argv._[0] === 'help'){
var cmd = argv._[1];
if(cmd && ['init', 'cat', 'clone', 'get', 'install', 'validate'].indexOf(cmd) !== -1){
if(cmd && ['init', 'cat', 'clone', 'get', 'install', 'validate', 'ckan'].indexOf(cmd) !== -1){
console.log(fs.readFileSync(path.join(path.dirname(__dirname), 'doc', 'command-' + cmd + '.md'), 'utf8'));
} else {
console.log(optimist.help());
}

} else {

_fail(new Error('invalid command'));

};

function _fail(err){
Expand Down
9 changes: 9 additions & 0 deletions doc/command-ckan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Push the Data Package in the current directory into CKAN.

This will also import data from the Data Package resources into the DataStore
(if of appropriate format i.e. CSVs).

If you need to set the owner organization in CKAN use --owner_org e.g.

dpm ckan http://datahub.io --owner_org=my-organization

22 changes: 22 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var crypto = require('crypto')
, jtsInfer = require('jts-infer')
, validator = require('datapackage-validate')
, dpRead = require('datapackage-read')
, dpCkan = require('datapackage-ckan')
;


Expand Down Expand Up @@ -216,4 +217,25 @@ Dpm.prototype.get = function(dpkgId, opts, callback) {
});
};

Dpm.prototype.ckan = function(argv, callback) {
var ckanUrlOrName = argv._[1]
, dpPath = this.root
;

// convert configs keyed by name to ones keyed by urls ...
var ckanConfigs = {};
for(key in this.config.ckan) {
ckanConfigs[this.config.ckan[key].url] = this.config.ckan[key];
};
var config = ckanConfigs[ckanUrlOrName] || this.config.ckan[ckanUrlOrName];

if (!config) {
var msg = 'You need to set a CKAN API Key for CKAN instance ' + ckanUrlOrName +'. See help on ckan command for how to do this.';
callback(msg);
return;
}

var ckanIt = new dpCkan.Pusher(config.url, config.apikey);
ckanIt.push(dpPath, argv, callback);
};

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"datapackage-init": "",
"datapackage-validate": ">=0.2.2",
"datapackage-read": "",
"datapackage-ckan": "",
"glob": "~3.2.7",
"lodash.uniq": "~2.4.1",
"lodash.flatten": "~2.4.1",
Expand Down

0 comments on commit 9f79f48

Please sign in to comment.