Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Add :rkd:create-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed May 3, 2020
1 parent a8ee943 commit 42db7d9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/source/standardlib/technical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ to create a task by defining a simple method as a callback.

.. literalinclude:: ../../examples/callback/.rkd/makefile.py


:rkd:create-structure
~~~~~~~~~~~~~~~~~~~~~

Creates a template structure used by RKD in current directory.

9 changes: 3 additions & 6 deletions src/rkd/internal/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Base RKD Makefile, contains basic commands such as :tasks, :clean or :version
#

from rkd.syntax import TaskDeclaration, TaskAliasDeclaration
from rkd.standardlib.python import PublishTask, BuildTask
from rkd.syntax import TaskDeclaration
from rkd.standardlib.shell import ShellCommand, ExecProcessCommand
from rkd.standardlib import InitTask, TasksListingTask, CallableTask, VersionTask
from rkd.standardlib import InitTask, TasksListingTask, VersionTask, CreateStructureTask


IMPORTS = [
Expand All @@ -14,9 +13,7 @@
TaskDeclaration(InitTask()),
TaskDeclaration(TasksListingTask()),
TaskDeclaration(VersionTask()),

TaskDeclaration(PublishTask()),
TaskDeclaration(BuildTask())
TaskDeclaration(CreateStructureTask())
]

TASKS = [
Expand Down
29 changes: 29 additions & 0 deletions src/rkd/misc/initial-structure/.rkd/makefile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import os
from rkd.syntax import TaskAliasDeclaration as Task, TaskDeclaration
from rkd.standardlib.python import imports as PythonImports
from rkd.standardlib.docker import imports as DockerImports
from rkd.standardlib import CallableTask
from rkd.contract import ExecutionContext


def create_union_task_as_method(context: ExecutionContext) -> bool:
os.system('xdg-open https://iwa-ait.org')
return True


# optionally, import docker-related and python-related tasks from Python packages
IMPORTS = [] + PythonImports() + DockerImports()

# optionally, add a custom task written in pure Python
IMPORTS += [TaskDeclaration(CallableTask(':create-union', create_union_task_as_method))]

# optionally, create own tasks that are using other tasks
TASKS = [
Task(':hello-world', [':sh', '-c', '''
set -x
MSG="Hello world"
echo "${MSG}"
'''])
]
24 changes: 24 additions & 0 deletions src/rkd/standardlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import pkg_resources
import os
from argparse import ArgumentParser
from typing import Callable
from ..contract import TaskInterface, ExecutionContext, TaskDeclarationInterface
Expand Down Expand Up @@ -154,3 +155,26 @@ def execute(self, context: ExecutionContext) -> bool:

return True


class CreateStructureTask(TaskInterface):
""" Creates a file structure in current directory """

def get_name(self) -> str:
return ':create-structure'

def get_group_name(self) -> str:
return ':rkd'

def configure_argparse(self, parser: ArgumentParser):
pass

def execute(self, context: ExecutionContext) -> bool:
if os.path.isdir('.rkd'):
self._io.error_msg('Structure already created - ".rkd" directory is present')
return False

self._io.info_msg('Creating a folder structure at %s' % os.getcwd())
template_structure_path = os.path.dirname(os.path.realpath(__file__)) + '/../misc/initial-structure'
self.sh('cp -pr %s/.rkd ./' % template_structure_path, verbose=True)

return True

0 comments on commit 42db7d9

Please sign in to comment.