pip install fabric
# -*- coding: utf-8 -*- from fabric.api import local, prompt, settings env.test_branch = 'test' env.dev_branch = 'dev' def commit(): """ . """ with settings(warn_only=True): local('git status') prompt('Press <Enter> to continue or <Ctrl+C> to cancel.') # , # local('git add .') local('git commit') # def merge_dev_to_test(with_return=True): """ . """ local('git checkout %s' % env.test_branch) # local('git merge --no-ff %s' % env.dev_branch) # if with_return: local('git checkout %s' % env.dev_branch) # def to_test() """ . """ commit() merge_dev_to_test()
merge_dev_to_test
very applied and it can be easily universalized.fab to_test
and the input of a comment in the editor. At the same time, he gives a preview - what changes will occur in the brunch and merges the developments from the development branch into the test one. If the merge is not needed - just perform fab commit
. # -*- coding: utf-8 -*- from os import path from fabric.api import env, local env.settings_files = ( path.join('projcet_root', 'settings.py'), path.join('projcet_root', 'module', 'settings.py'), ) env.settings_versions = { 'develop': '#-D', 'test': '#-T', 'production': '#-P', } def _commenter(c_type, filename, regex, use_sudo=False, char='#', backup='.bak'): """ . """ if use_sudo: sudoer = 'sudo ' else: sudoer = '' if regex.startswith('^'): regex = regex[1:] if regex.endswith('$'): regex = regex[:-1] if c_type == 'comment': replacement = '%s ' % char char = '[^%s ]' % char regex = '(%s.+%s.*)' % (char, regex) else: replacement = '' regex = r'%s ?(.+%s.*)' % (char, regex) local(r"{sudo}sed -i{backup} -r -e 's/^([[:space:]]*){regex}$/" r"\1{replacement}\2/g' {filename}".format(**{ 'sudo': sudoer, 'backup': backup, 'replacement': replacement, 'regex': regex, 'filename': filename, })) def lcomment(*args, **kwargs): """ . """ _commenter('comment', *args, **kwargs) def luncomment(*args, **kwargs): """ . """ _commenter('uncomment', *args, **kwargs) def update_settings(mode): """ . """ for filename in env.settings_files: for version in env.settings_versions: if mode == version: luncomment(filename, versions[version]) elif: lcomment(filename, versions[version])
fabric
itself, there is a contrib.files
module with the comment
function, which, by and large, repeats the “commentator” with the difference that it works locally, and comments place not at the beginning of the line, but insert a space between the comment character and the text (like this makes sublime text ) and only looks for a marker at the end of the line.fab update_settings:mode=<>
command, he has to bypass the files in the env.settings_files
list on the way, uncommenting the lines with the marker to the appropriate mode and commenting with the marker that is not appropriate.fab update_settings:mode=test
will run through the files /project_root/settings.py
and /project_root/module/settings.py
commenting on lines ending in '# -D' and '# -P' and uncommenting ending in '# -T' . DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'dvl', # #-D # 'NAME': 'prd', # #-P # 'NAME': 'tst', # #-T 'USER': 'ruutt', 'PASSWORD': 'gigopasswort', 'CHARSET': 'UTF8', }, }
def deploy(branch): env.test_branch =branch # commit(False) # , update_settings(branch) # # , , .. local('git checkout %s' % env.dev_branch) # prompt("OK. Press any <Enter> to exit.") # IDE - # .
fab deploy:branch=test
. Count how many commands in the console and the time spent on them will be saved, I leave to you.Source: https://habr.com/ru/post/141271/
All Articles