summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--distixlib/plugins/init_plugin.py64
-rw-r--r--without-tests1
-rw-r--r--yarns/030-init.yarn12
-rw-r--r--yarns/900-implements.yarn9
4 files changed, 86 insertions, 0 deletions
diff --git a/distixlib/plugins/init_plugin.py b/distixlib/plugins/init_plugin.py
new file mode 100644
index 0000000..028eac9
--- /dev/null
+++ b/distixlib/plugins/init_plugin.py
@@ -0,0 +1,64 @@
+# Copyright 2014 Lars Wirzenius
+#
+# 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, either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import os
+
+import cliapp
+
+import distixlib
+
+
+class InitPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand(
+ 'init', self.init, arg_synopsis='DIR [DESCRIPTION]')
+
+ def disable(self):
+ pass
+
+ def init(self, args):
+ '''Create and initialise a new repository.'''
+
+ dirname = args[0]
+ if len(args) > 1:
+ description = args[1]
+ else:
+ description = ''
+
+ os.mkdir(dirname)
+ self._create_repo_yaml(dirname, description)
+ self._git_init(dirname)
+ self._git_add_and_commit_files(dirname)
+
+ def _create_repo_yaml(self, dirname, description):
+ metadata = distixlib.Metadata()
+ metadata.add('description', description)
+ serialiser = distixlib.MetadataSerialiser()
+ text = serialiser.serialise(metadata)
+ with open(os.path.join(dirname, 'repo.yaml'), 'w') as f:
+ f.write(text)
+
+ def _git_init(self, dirname):
+ cliapp.runcmd(['git', 'init'], cwd=dirname, stdout=None, stderr=None)
+
+ def _git_add_and_commit_files(self, dirname):
+ cliapp.runcmd(['git', 'add', '.'], cwd=dirname, stdout=None, stderr=None)
+ cliapp.runcmd(
+ ['git', 'commit', '-m', 'distix initial commit'],
+ cwd=dirname, stdout=None, stderr=None)
diff --git a/without-tests b/without-tests
index 797d45d..bd29200 100644
--- a/without-tests
+++ b/without-tests
@@ -1,4 +1,5 @@
setup.py
distixlib/app.py
distixlib/__init__.py
+distixlib/plugins/init_plugin.py
distixlib/plugins/metadata_manipulation_plugin.py
diff --git a/yarns/030-init.yarn b/yarns/030-init.yarn
new file mode 100644
index 0000000..bf4cc88
--- /dev/null
+++ b/yarns/030-init.yarn
@@ -0,0 +1,12 @@
+Initialising a repository
+=========================
+
+This chapter contains scenarios for testing the initialisation and
+creation of a repository.
+
+ SCENARIO create a repository
+ WHEN user attempts to run distix init REPO
+ THEN attempt succeeded
+ AND REPO exists
+ AND REPO/.git exists
+ AND REPO/repo.yaml exists
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index 14ad7ff..cc4c003 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -67,3 +67,12 @@ content.
IMPLEMENTS GIVEN file (\S+) containing "(.*)"
printf "$MATCH_2" > "$DATADIR/$MATCH_1"
+
+
+File tests
+-----------
+
+Does a file or directory exist?
+
+ IMPLEMENTS THEN (\S+) exists
+ test -e "$DATADIR/$MATCH_1"