SVNProvider downloads repository in resources-directory from config

This commit is contained in:
Dmitry Shulyak 2015-08-05 11:46:16 +03:00
parent b92672b30e
commit 276f58fb4f
3 changed files with 25 additions and 8 deletions

View File

@ -16,3 +16,4 @@ Fabric==1.10.2
tabulate==0.7.5 tabulate==0.7.5
ansible ansible
celery celery
mock

View File

@ -6,17 +6,27 @@ from ansible.playbook import PlayBook
from ansible import utils from ansible import utils
from ansible import callbacks from ansible import callbacks
import ansible.constants as C import ansible.constants as C
from fabric import api as fabric_api
from solar.core.handlers import base from solar.core.handlers import base
from solar import errors from solar import errors
from solar.core.provider import SVNProvider from solar.core.provider import SVNProvider
ROLES_PATH = '/etc/ansible/roles'
class AnsiblePlaybook(base.BaseHandler): class AnsiblePlaybook(base.BaseHandler):
def download_roles(self, urls): def download_roles(self, urls):
if not os.path.exists(ROLES_PATH):
os.makedirs(ROLES_PATH)
for url in urls: for url in urls:
SVNProvider(url, '/etc/ansible/roles').run() provider = SVNProvider(url)
provider.run()
fabric_api.local('cp -r {} {}'.format(
provider.repo_directory, ROLES_PATH))
def action(self, resource, action): def action(self, resource, action):
action_file = os.path.join( action_file = os.path.join(

View File

@ -110,16 +110,22 @@ class SVNProvider(BaseProvider):
but with svn you can but with svn you can
""" """
def __init__(self, url, path='.'): def __init__(self, url, path='.', base_path=None):
self.url = url self.url = url
self.path = path self.path = path
self.base_path = base_path or utils.read_config()['resources-directory']
if path != '.':
self.directory = os.path.join(self.base_path, path)
else:
self.directory = self.base_path
self.repo_directory = os.path.join(self.directory, self.url.rsplit('/', 1)[-1])
def run(self): def run(self):
if not os.path.exists(self.path): if not os.path.exists(self.directory):
os.makedirs(self.path) os.makedirs(self.directory)
full_path_role = os.path.join(self.path, self.url.rsplit('/', 1)[-1])
if not os.path.exists(full_path_role): if not os.path.exists(self.repo_directory):
fabric_api.local( fabric_api.local(
'cd {path} && svn checkout {url}'.format( 'cd {dir} && svn checkout {url}'.format(
path=self.path, dir=self.directory,
url=self.url)) url=self.url))