Cloner
The cloner module for the Blueprint Cloner.
- class blueprint_cloner.cloner.Cloner(name, blueprint='django', version='master', namespace=None, directory=None)
The cloner class which can be used to create a new Git(Lab) project from a blueprint, or to upgrade an existing project to a newer version of the blueprint.
- Parameters
name (str) – The case-sensitive verbose name of the new project (i.e. “Foo Bar”)
blueprint (str) – The name of a blueprint project
version (str) – The version of the blueprint project
namespace (str) – The GitLab namespace of the project
directory (str) – The directory where the project should be cloned to
- classmethod build_names_and_substitutes(name, blueprint)
Build all different variants of the project name, as well as the substitutes from the blueprint names to the project names.
This method leverages
Cloner.build_project_names()
to create all the project & blueprint names.- Parameters
name (str) – The project’s name
blueprint (str) – The blueprint name
- Returns
The project names and substitutes
- Return type
tuple[dict, dict]
Hint
Example:
>>> names, substitutes = Cloner.build_names_and_substitutes('Foo Bar', 'Example') >>> substitutes['Example Blueprint'] 'Foo Bar' >>> substitutes['example blueprint'] 'foo bar' >>> substitutes['EXAMPLE BLUEPRINT'] 'FOO BAR' >>> substitutes['exampleBlueprint'] 'fooBar' >>> substitutes['ExampleBlueprint'] 'FooBar' >>> substitutes['example_blueprint'] 'foo_bar' >>> substitutes['EXAMPLE_BLUEPRINT'] 'FOO_BAR' >>> substitutes['example-blueprint'] 'foo-bar' >>> substitutes['EXAMPLE-BLUEPRINT'] 'FOO-BAR'
- classmethod build_project_names(name)
Build all different variants of the project name.
- Parameters
name (str) – The project’s name
- Returns
All case style variants of the project name
- Return type
dict
Hint
Example:
>>> names = Cloner.build_project_names('Foo Bar') >>> names['Title Case'] 'Foo Bar' >>> names['lower case'] 'foo bar' >>> names['UPPER CASE'] 'FOO BAR' >>> names['camelCase'] 'fooBar' >>> names['PascalCase'] 'FooBar' >>> names['lower_snake_case'] 'foo_bar' >>> names['UPPER_SNAKE_CASE'] 'FOO_BAR' >>> names['lower-kebap-case'] 'foo-bar' >>> names['UPPER-KEBAP-CASE'] 'FOO-BAR'
- clone(skip_push=False)
Clone the blueprint and create a new (Git)Lab project.
- Parameters
skip_push (bool) – Should the push to GitLab be skipped
See also
This method is basically a wrapper for the following methods:
- create_upgrade_branch()
Create a new upgrade branch and sync the files of the blueprint to it.
The files of
self.blueprint_directory
will be rsynced into the root of the Git repository ofself.directory
.See also
The upgrade commit will be commited in the
blueprint_cloner.settings.UPGRADE_BRANCH
with theblueprint_cloner.settings.UPGRADE_COMMIT
message.
- download_blueprint()
Download a copy of the blueprint repository from
self.blueprint_url
and store it in theself.directory
.See also
The blueprint is downloaded from the
blueprint_cloner.settings.BLUEPRINT_URL
URL.
- classmethod fetch_blueprint_projects()
Fetch all available blueprint projects.
See also
The available blueprints are automatically fetched from the
blueprint_cloner.settings.BLUEPRINT_PROJECTS_URL
URL.- Returns
The blueprint projects as tuple
- Return type
generator
- property info
All informations nicely formatted based on the arguments used to create the cloner instance.
- Returns
The informations
- Return type
str
- init_git_project()
Change into the
self.directory
, initialise a new Git repository and commit all the files.See also
The initial commit will be commited with the
blueprint_cloner.settings.INIT_COMMIT
message.
- load_default_namespace()
Load the default namespace for the project from the
namespace
file in the blueprint’s meta directory or use the cloner’s default namespace.See also
The name of the meta directory is defined in
blueprint_cloner.settings.META_DIRECTORY
. The default namespace of the cloner is defined inblueprint_cloner.settings.DEFAULT_NAMESPACE
.- Returns
The default namespace
- Return type
str
- move_blueprint_directory()
Move the blueprint directory created by
Cloner.download_blueprint()
to the destination directorydirectory
.
- process_renames(root, filelist, replace_content)
Loop through the
filelist
in theroot
directory and rename the directories and files. In casereplace_content
is set toTrue
, occurences in the files are also renamed.- Parameters
root (str) – The root directory path
filelist (list) – The filelist to process
replace_content (bool) – Replace the content of the file
See also
Have a look at the
Cloner.build_names_and_substitutes()
method for the substitutes.
- push_git_project()
Push the Git project to the remote repository URL
self.project_url
.See also
The remote repository URL is defined in
blueprint_cloner.settings.PROJECT_URL
.
- remove_meta_directory()
Remove blueprint cloner meta directory from the project’s directory.
See also
The name of the meta directory is defined in
blueprint_cloner.settings.META_DIRECTORY
.
- rename_blueprint()
Loop through the project directory
self.directory
and rename all occurences of the blueprint names in filenames, directory names and the files itself.The rename is done by
Cloner.process_renames()
.
- classmethod run(command)
Run the
command
on the shell.- Parameters
command (str) – The command to run
- Returns
The stdout output
- Return type
str
- Raises
CommandError – When the command fails
- run_post_scripts()
Run post scripts of the blueprint and clean them afterwards.
See also
Post scripts are found under the
post.d/
directory in theblueprint_cloner.settings.META_DIRECTORY
.
- upgrade()
Clone the blueprint as in
Cloner.clone()
, but instead of initialising & committing a new Git project, upgrade an existing one.See also
This method is basically a wrapper for the following methods:
When the project upgrade worked, the new files are stored in the
blueprint_cloner.settings.UPGRADE_BRANCH
branch and theblueprint_cloner.settings.UPGRADE_MESSAGE
will be printed.
- verify_blueprint()
Verify the blueprint name & version.
- Raises
BlueprintClonerError – When the blueprint or version isn’t found
- verify_clone_conditions()
Verify that the
self.directory
directory isn’t existing yet.- Raises
BlueprintClonerError – When directory is already existing
- verify_upgrade_conditions()
Verify that the
self.directory
is a Git repository and that it’s in a clean state.- Raises
BlueprintClonerError – When directory isn’t a clean Git repository