diff options
author | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2013-11-22 23:17:55 +0000 |
---|---|---|
committer | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2013-11-24 16:37:53 +0000 |
commit | 32de681f84706224d597e7fb3d222000f642c455 (patch) | |
tree | 1164eb9b8ea5729e2b86e6fcaabd10346c8dee45 /morphlib | |
parent | b2b618f71d63290efbc849650459ce6cd467621d (diff) | |
download | morph-32de681f84706224d597e7fb3d222000f642c455.tar.gz |
starter for new lorry_pluginbaserock/ps/add-lorry
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/plugins/lorry_plugin.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/morphlib/plugins/lorry_plugin.py b/morphlib/plugins/lorry_plugin.py new file mode 100644 index 00000000..3e6d5e9d --- /dev/null +++ b/morphlib/plugins/lorry_plugin.py @@ -0,0 +1,67 @@ +# Copyright (C) 2013 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import os +import cliapp +import logging + +import morphlib +from morphlib.util import OrderedDict, json + +class LorryPlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand( + 'lorry', self._lorry, arg_synopsis='NAME URL TYPE [ARG...]') + + def disable(self): + pass + + def _lorry(self, args, **kwargs): + '''Ingest a new component into git in the Baserock way + + Command line arguments: + + * `NAME` is used for the resulting lorry file and git repo + * `URL` specifies the upstream (repo or tarball) + * `TYPE` specifies the upstream type eg tar, bzr, svn, git + * `ARG` is a Lorry command argument. + + This creates a NAME.lorry file, and then runs Lorry on it + + Example: + + morph foo http://code.liw.fi/foo/bzr/trunk/ bzr + + ''' + + if len(args) < 3: + raise cliapp.AppException('morph lorry needs a lorry name,' + ' url and type as paramaters') + chunk = args[0] + url = args[1] + type = args[2] + + lorrydir = os.path.join(self.app.settings['cachedir'],'lorries') + if not os.path.exists(lorrydir): + os.makedirs(lorrydir) + + lorry = {chunk: {'type': type, 'url': url}} + f = open(os.path.join(lorrydir, chunk + '.lorry'), "w") + f.write(json.dumps(lorry, indent=4, sort_keys=True)) + f.close() + + self.app.runcmd(['lorry', '--verbose', '--pull-only', f.name, + '-w', lorrydir], stdin=None, stdout=None, stderr=None) |