SVNProvider downloads repository in resources-directory from config
This commit is contained in:
parent
b92672b30e
commit
276f58fb4f
@ -16,3 +16,4 @@ Fabric==1.10.2
|
||||
tabulate==0.7.5
|
||||
ansible
|
||||
celery
|
||||
mock
|
||||
|
@ -6,17 +6,27 @@ from ansible.playbook import PlayBook
|
||||
from ansible import utils
|
||||
from ansible import callbacks
|
||||
import ansible.constants as C
|
||||
from fabric import api as fabric_api
|
||||
|
||||
from solar.core.handlers import base
|
||||
from solar import errors
|
||||
from solar.core.provider import SVNProvider
|
||||
|
||||
|
||||
ROLES_PATH = '/etc/ansible/roles'
|
||||
|
||||
|
||||
class AnsiblePlaybook(base.BaseHandler):
|
||||
|
||||
def download_roles(self, urls):
|
||||
if not os.path.exists(ROLES_PATH):
|
||||
os.makedirs(ROLES_PATH)
|
||||
|
||||
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):
|
||||
action_file = os.path.join(
|
||||
|
@ -110,16 +110,22 @@ class SVNProvider(BaseProvider):
|
||||
but with svn you can
|
||||
"""
|
||||
|
||||
def __init__(self, url, path='.'):
|
||||
def __init__(self, url, path='.', base_path=None):
|
||||
self.url = url
|
||||
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):
|
||||
if not os.path.exists(self.path):
|
||||
os.makedirs(self.path)
|
||||
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.directory):
|
||||
os.makedirs(self.directory)
|
||||
|
||||
if not os.path.exists(self.repo_directory):
|
||||
fabric_api.local(
|
||||
'cd {path} && svn checkout {url}'.format(
|
||||
path=self.path,
|
||||
'cd {dir} && svn checkout {url}'.format(
|
||||
dir=self.directory,
|
||||
url=self.url))
|
||||
|
Loading…
Reference in New Issue
Block a user