begin to make OBJECT_MARKER dynamic

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2014-05-06 00:28:18 +02:00
parent 78c3c09163
commit c363fc24de
4 changed files with 23 additions and 10 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2010-2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -23,7 +24,6 @@ from cdist.core.cdist_type import CdistType
from cdist.core.cdist_type import NoSuchTypeError
from cdist.core.cdist_object import CdistObject
from cdist.core.cdist_object import IllegalObjectIdError
from cdist.core.cdist_object import OBJECT_MARKER
from cdist.core.explorer import Explorer
from cdist.core.manifest import Manifest
from cdist.core.code import Code

View file

@ -32,9 +32,6 @@ from cdist.util import fsproperty
log = logging.getLogger(__name__)
OBJECT_MARKER = '.cdist'
class IllegalObjectIdError(cdist.Error):
def __init__(self, object_id, message=None):
self.object_id = object_id
@ -66,16 +63,18 @@ class CdistObject(object):
STATE_RUNNING = "running"
STATE_DONE = "done"
def __init__(self, cdist_type, base_path, object_id=''):
def __init__(self, cdist_type, base_path, object_marker=".cdist", object_id=''):
self.cdist_type = cdist_type # instance of Type
self.base_path = base_path
self.object_id = object_id
self.object_marker = object_marker
self.validate_object_id()
self.sanitise_object_id()
self.name = self.join_name(self.cdist_type.name, self.object_id)
self.path = os.path.join(self.cdist_type.path, self.object_id, OBJECT_MARKER)
self.path = os.path.join(self.cdist_type.path, self.object_id, self.object_marker)
self.absolute_path = os.path.join(self.base_path, self.path)
self.code_local_path = os.path.join(self.path, "code-local")
self.code_remote_path = os.path.join(self.path, "code-remote")
@ -97,7 +96,7 @@ class CdistObject(object):
def list_object_names(cls, object_base_path):
"""Return a list of object names"""
for path, dirs, files in os.walk(object_base_path):
if OBJECT_MARKER in dirs:
if self.object_marker in dirs:
yield os.path.relpath(path, object_base_path)
@staticmethod
@ -127,8 +126,8 @@ class CdistObject(object):
"""Validate the given object_id and raise IllegalObjectIdError if it's not valid.
"""
if self.object_id:
if OBJECT_MARKER in self.object_id.split(os.sep):
raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER)
if self.object_marker in self.object_id.split(os.sep):
raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % self.object_marker)
if '//' in self.object_id:
raise IllegalObjectIdError(self.object_id, 'object_id may not contain //')
if self.object_id == '.':

View file

@ -0,0 +1,14 @@
Change object marker from .cdist to .cdist-TEMPNAME to allow using
object ids that contain / are .cdist.
Changes required:
cdist/emulator.py:
needs to know suffix/name
tests:
allow object id named /.cdist
tests:
many
cdist/config.py:
have suffix