Skip to content

Commit

Permalink
Systematically use rel_path for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nbraud committed Sep 12, 2016
1 parent d8c831a commit 90da634
Show file tree
Hide file tree
Showing 47 changed files with 110 additions and 164 deletions.
8 changes: 3 additions & 5 deletions bootstrapvz/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ def validate_manifest(data, validator, error):
:param function validator: The function that validates the manifest given the data and a path
:param function error: The function tha raises an error when the validation fails
"""
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))

from bootstrapvz.common.releases import get_release
from bootstrapvz.common.releases import squeeze
from bootstrapvz.common.releases import get_release, squeeze
release = get_release(data['system']['release'])

if release < squeeze:
Expand Down
6 changes: 2 additions & 4 deletions bootstrapvz/base/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
invocations should have etc..
"""
from bootstrapvz.common.exceptions import ManifestError
from bootstrapvz.common.tools import load_data
from bootstrapvz.common.tools import load_data, rel_path
import logging
log = logging.getLogger(__name__)

Expand All @@ -28,9 +28,7 @@ def __init__(self, path=None, data=None):
raise ManifestError('`path\' or `data\' must be provided')
self.path = path

import os.path
self.metaschema = load_data(os.path.normpath(os.path.join(os.path.dirname(__file__),
'metaschema.json')))
self.metaschema = load_data(rel_path(__file__, 'metaschema.json'))

self.load_data(data)
self.load_modules()
Expand Down
8 changes: 4 additions & 4 deletions bootstrapvz/base/tasklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ def get_all_tasks(loaded_modules):
import pkgutil
import os.path
import bootstrapvz
bootstrapvz_root = os.path.dirname(bootstrapvz.__file__)
module_paths = set([(os.path.join(bootstrapvz_root, 'common/tasks'), 'bootstrapvz.common.tasks.')])
from bootstrapvz.common.tools import rel_path
module_paths = set([(rel_path(bootstrapvz.__file__, 'common/tasks'), 'bootstrapvz.common.tasks.')])

for module in loaded_modules:
module_path = os.path.dirname(module.__file__)
module_prefix = module.__name__ + '.'
module_paths.add((module_path, module_prefix))

providers = os.path.join(os.path.dirname(bootstrapvz.__file__), 'providers')
providers = rel_path(bootstrapvz.__file__, 'providers')
for module_loader, module_name, ispkg in pkgutil.iter_modules([providers, 'bootstrapvz.providers']):
module_path = os.path.join(module_loader.path, module_name)
# The prefix param seems to do nothing, so we prefix the module name ourselves
module_prefix = 'bootstrapvz.providers.{}.'.format(module_name)
module_paths.add((module_path, module_prefix))

plugins = os.path.join(os.path.dirname(bootstrapvz.__file__), 'plugins')
plugins = rel_path(bootstrapvz.__file__, 'plugins')
for module_loader, module_name, ispkg in pkgutil.iter_modules([plugins, 'bootstrapvz.plugins']):
module_path = os.path.join(module_loader.path, module_name)
module_prefix = 'bootstrapvz.plugins.{}.'.format(module_name)
Expand Down
4 changes: 2 additions & 2 deletions bootstrapvz/common/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import os.path
from bootstrapvz.common.tools import rel_path

assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))
assets = rel_path(__file__, '../assets')
4 changes: 2 additions & 2 deletions bootstrapvz/common/tasks/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ConfigureNetworkIF(Task):

@classmethod
def run(cls, info):
network_config_path = os.path.join(os.path.dirname(__file__), 'network-configuration.yml')
from ..tools import config_get
from ..tools import config_get, rel_path
network_config_path = rel_path(__file__, 'network-configuration.yml')
if_config = config_get(network_config_path, [info.manifest.release.codename])

interfaces_path = os.path.join(info.root, 'etc/network/interfaces')
Expand Down
6 changes: 2 additions & 4 deletions bootstrapvz/plugins/admin_user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
def validate_manifest(data, validator, error):
import os.path

schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/ansible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/apt_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/chef/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/cloud_init/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
8 changes: 3 additions & 5 deletions bootstrapvz/plugins/debconf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
def validate_manifest(data, validator, error):
from bootstrapvz.common.tools import log_check_call
import os.path
schema_path = os.path.join(os.path.dirname(__file__),
'schema.yaml')
validator(data, schema_path)
from bootstrapvz.common.tools import log_check_call, rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))

log_check_call(['debconf-set-selections', '--checkonly'],
stdin=data['plugins']['debconf'])

Expand Down
6 changes: 3 additions & 3 deletions bootstrapvz/plugins/docker_daemon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os.path
from bootstrapvz.common.tools import rel_path
import tasks
from bootstrapvz.common.tasks import apt
from bootstrapvz.common.releases import wheezy


def validate_manifest(data, validator, error):
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
validator(data, rel_path(__file__, 'manifest-schema.yml'))

from bootstrapvz.common.releases import get_release
if get_release(data['system']['release']) == wheezy:
# prefs is a generator of apt preferences across files in the manifest
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/docker_daemon/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from bootstrapvz.common import phases
from bootstrapvz.common.tasks import grub
from bootstrapvz.common.tasks import initd
from bootstrapvz.common.tools import log_check_call
from bootstrapvz.common.tools import sed_i
from bootstrapvz.common.tools import log_check_call, sed_i, rel_path
import os
import os.path
import shutil
import subprocess
import time

ASSETS_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), 'assets'))
ASSETS_DIR = rel_path(__file__, 'assets')


class AddDockerDeps(Task):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/ec2_launch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/ec2_publish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/file_copy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@


def validate_manifest(data, validator, error):
import os.path
from bootstrapvz.common.tools import rel_path

schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/google_cloud_repo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import tasks
import os.path
from bootstrapvz.common.tools import rel_path


def validate_manifest(data, validator, error):
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
6 changes: 3 additions & 3 deletions bootstrapvz/plugins/minimize_size/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema.yml')
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))

if data['plugins']['minimize_size'].get('shrink', False) and data['volume']['backing'] != 'vmdk':
error('Can only shrink vmdk images', ['plugins', 'minimize_size', 'shrink'])

Expand Down
4 changes: 2 additions & 2 deletions bootstrapvz/plugins/minimize_size/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import os
from bootstrapvz.common.tools import rel_path

assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))
assets = rel_path(__file__, '../assets')
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/ntp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/pip_install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/prebootstrapped/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/puppet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/root_password/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/salt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/plugins/unattended_upgrades/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
9 changes: 3 additions & 6 deletions bootstrapvz/plugins/vagrant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import tasks
from bootstrapvz.common import task_groups
from bootstrapvz.common.tasks import image
from bootstrapvz.common.tasks import ssh
from bootstrapvz.common.tasks import volume
import os
from bootstrapvz.common.tasks import image, ssh, volume
from bootstrapvz.common.tools import rel_path


def validate_manifest(data, validator, error):
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
3 changes: 2 additions & 1 deletion bootstrapvz/plugins/vagrant/tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from bootstrapvz.base import Task
from bootstrapvz.common import phases
from bootstrapvz.common.tasks import workspace
from bootstrapvz.common.tools import rel_path
import os
import shutil

assets = os.path.normpath(os.path.join(os.path.dirname(__file__), 'assets'))
assets = rel_path(__file__, 'assets')


class CheckBoxPath(Task):
Expand Down
5 changes: 2 additions & 3 deletions bootstrapvz/providers/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@


def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
validator(data, schema_path)
from bootstrapvz.common.tools import rel_path
validator(data, rel_path(__file__, 'manifest-schema.yml'))


def resolve_tasks(taskset, manifest):
Expand Down
4 changes: 2 additions & 2 deletions bootstrapvz/providers/azure/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import os.path
from bootstrapvz.common.tools import rel_path

assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))
assets = rel_path(__file__, '../assets')
Loading

0 comments on commit 90da634

Please sign in to comment.