Fix for #300 (version 1, no tests)

Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
This commit is contained in:
Nico Schottelius 2015-02-23 16:40:50 +01:00
parent 49040c8044
commit ccc3c02466
6 changed files with 49 additions and 17 deletions

View file

@ -41,6 +41,9 @@ BANNER = """
"P' "" "" "P' "" ""
""" """
# File that contains the name of the object marker
OBJECT_MARKER_NAME = '.object_marker'
REMOTE_COPY = "scp -o User=root -q" REMOTE_COPY = "scp -o User=root -q"
REMOTE_EXEC = "ssh -o User=root -q" REMOTE_EXEC = "ssh -o User=root -q"

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) # 2010-2015 Nico Schottelius (nico-cdist at schottelius.org)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -161,8 +161,9 @@ class Config(object):
def object_list(self): def object_list(self):
"""Short name for object list retrieval""" """Short name for object list retrieval"""
for cdist_object in core.CdistObject.list_objects(self.local.object_path, for cdist_object in core.CdistObject.list_objects(object_base_path=self.local.object_path,
self.local.type_path): type_base_path=self.local.type_path,
object_marker_name=self.local.object_marker_name):
if cdist_object.cdist_type.is_install: if cdist_object.cdist_type.is_install:
self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object)) self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object))
else: else:

View file

@ -23,7 +23,7 @@ from cdist.core.cdist_type import CdistType
from cdist.core.cdist_type import NoSuchTypeError from cdist.core.cdist_type import NoSuchTypeError
from cdist.core.cdist_object import CdistObject from cdist.core.cdist_object import CdistObject
from cdist.core.cdist_object import IllegalObjectIdError from cdist.core.cdist_object import IllegalObjectIdError
from cdist.core.cdist_object import OBJECT_MARKER #from cdist.core.cdist_object import OBJECT_MARKER
from cdist.core.explorer import Explorer from cdist.core.explorer import Explorer
from cdist.core.manifest import Manifest from cdist.core.manifest import Manifest
from cdist.core.code import Code from cdist.core.code import Code

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz) # 2014 Daniel Heule (hda at sfs.biz)
# #
# This file is part of cdist. # This file is part of cdist.
@ -32,9 +32,6 @@ from cdist.util import fsproperty
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
OBJECT_MARKER = '.cdist'
class IllegalObjectIdError(cdist.Error): class IllegalObjectIdError(cdist.Error):
def __init__(self, object_id, message=None): def __init__(self, object_id, message=None):
self.object_id = object_id self.object_id = object_id
@ -71,20 +68,39 @@ class CdistObject(object):
self.base_path = base_path self.base_path = base_path
self.object_id = object_id self.object_id = object_id
self._init_object_marker_name()
self.validate_object_id() self.validate_object_id()
self.sanitise_object_id() self.sanitise_object_id()
self.name = self.join_name(self.cdist_type.name, self.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._init_paths()
def _init_object_marker_name(self):
self.object_marker_path = os.path.join(self.base_path, cdist.OBJECT_MARKER_NAME)
with open(self.object_marker_path, 'r') as fd:
object_marker_name = fd.readlines()
self.object_marker_name = object_marker_name[0].rstrip()
def _init_paths(self):
self.path = os.path.join(self.cdist_type.path, self.object_id, self.object_marker_name)
self.absolute_path = os.path.join(self.base_path, self.path) self.absolute_path = os.path.join(self.base_path, self.path)
self.code_local_path = os.path.join(self.path, "code-local") self.code_local_path = os.path.join(self.path, "code-local")
self.code_remote_path = os.path.join(self.path, "code-remote") self.code_remote_path = os.path.join(self.path, "code-remote")
self.parameter_path = os.path.join(self.path, "parameter") self.parameter_path = os.path.join(self.path, "parameter")
@classmethod @classmethod
def list_objects(cls, object_base_path, type_base_path): def list_objects(cls, object_base_path, type_base_path, object_marker_name):
"""Return a list of object instances""" """Return a list of object instances"""
for object_name in cls.list_object_names(object_base_path): for object_name in cls.list_object_names(object_base_path, object_marker_name):
type_name, object_id = cls.split_name(object_name) type_name, object_id = cls.split_name(object_name)
yield cls(cdist.core.CdistType(type_base_path, type_name), object_base_path, object_id=object_id) yield cls(cdist.core.CdistType(type_base_path, type_name), object_base_path, object_id=object_id)
@ -94,10 +110,10 @@ class CdistObject(object):
return os.listdir(object_base_path) return os.listdir(object_base_path)
@classmethod @classmethod
def list_object_names(cls, object_base_path): def list_object_names(cls, object_base_path, object_marker_name):
"""Return a list of object names""" """Return a list of object names"""
for path, dirs, files in os.walk(object_base_path): for path, dirs, files in os.walk(object_base_path):
if OBJECT_MARKER in dirs: if object_marker_name in dirs:
yield os.path.relpath(path, object_base_path) yield os.path.relpath(path, object_base_path)
@staticmethod @staticmethod
@ -127,7 +143,7 @@ class CdistObject(object):
"""Validate the given object_id and raise IllegalObjectIdError if it's not valid. """Validate the given object_id and raise IllegalObjectIdError if it's not valid.
""" """
if self.object_id: if self.object_id:
if OBJECT_MARKER in self.object_id.split(os.sep): if self.object_marker_name in self.object_id.split(os.sep):
raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER) raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER)
if '//' in self.object_id: if '//' in self.object_id:
raise IllegalObjectIdError(self.object_id, 'object_id may not contain //') raise IllegalObjectIdError(self.object_id, 'object_id may not contain //')

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # 2012 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Daniel Heule (hda at sfs.biz) # 2014 Daniel Heule (hda at sfs.biz)
# #

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -66,9 +66,9 @@ class Local(object):
self._init_log() self._init_log()
self._init_permissions() self._init_permissions()
self._init_paths() self._init_paths()
self._init_object_marker()
self._init_conf_dirs() self._init_conf_dirs()
@property @property
def dist_conf_dir(self): def dist_conf_dir(self):
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
@ -103,6 +103,12 @@ class Local(object):
self.type_path = os.path.join(self.conf_path, "type") self.type_path = os.path.join(self.conf_path, "type")
def _init_object_marker(self):
# Does not need to be secure - just randomly different from .cdist
self.object_marker_file = os.path.join(self.object_path, cdist.OBJECT_MARKER_NAME)
self.object_marker_name = tempfile.mktemp(prefix='.cdist-', dir='')
def _init_conf_dirs(self): def _init_conf_dirs(self):
self.conf_dirs = [] self.conf_dirs = []
@ -125,6 +131,7 @@ class Local(object):
def _init_directories(self): def _init_directories(self):
self.mkdir(self.conf_path) self.mkdir(self.conf_path)
self.mkdir(self.global_explorer_out_path) self.mkdir(self.global_explorer_out_path)
self.mkdir(self.object_path)
self.mkdir(self.bin_path) self.mkdir(self.bin_path)
def create_files_dirs(self): def create_files_dirs(self):
@ -133,6 +140,11 @@ class Local(object):
self._create_messages() self._create_messages()
self._link_types_for_emulator() self._link_types_for_emulator()
with open(self.object_marker_file, 'w') as fd:
fd.write("%s\n" % self.object_marker_name)
print("%s %s\n" % (self.object_marker_file, self.object_marker_name))
def _init_cache_dir(self, cache_dir): def _init_cache_dir(self, cache_dir):
if cache_dir: if cache_dir: