Skip to content

Commit

Permalink
Rename AbstractBlock to Block; Block to CoreBlock
Browse files Browse the repository at this point in the history
This renaming makes the API package much clearer, since the highest level block
abstraction is unqualified, and specializations of it are given qualifiers.
  • Loading branch information
sirosen committed Aug 24, 2014
1 parent 6748aa4 commit d6d2dae
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 35 deletions.
1 change: 1 addition & 0 deletions salve/api/__init__.py
@@ -0,0 +1 @@
from salve.api.block import Block, CompiledBlock
7 changes: 6 additions & 1 deletion salve/api/block.py
Expand Up @@ -4,6 +4,7 @@

import abc

from salve.util.enum import Enum
from salve.util.six import with_metaclass


Expand Down Expand Up @@ -35,14 +36,18 @@ def execute(self):
pass # pragma: no cover


class AbstractBlock(with_metaclass(abc.ABCMeta)):
class Block(with_metaclass(abc.ABCMeta)):
"""
A block is the basic unit of configuration.
Typically, blocks describe files, SALVE manifests, patches, etc
This is an ABC that defines the common characteristics of all
blocks. Furthermore, it defines the methods that must be implemented
on a block by its author.
"""
# these are the valid types of block, and therefore the valid
# block identifiers (case insensitive)
types = Enum('FILE', 'MANIFEST', 'DIRECTORY')

@abc.abstractmethod
def has(self, attribute_name):
"""
Expand Down
17 changes: 6 additions & 11 deletions salve/block/__init__.py
Expand Up @@ -3,11 +3,10 @@
import abc
import os

from salve.api.block import AbstractBlock
from salve.api import Block

from salve.util.enum import Enum
from salve.util.error import SALVEException
import salve.util.locations as locations
from salve.util import locations

from salve.util.six import with_metaclass

Expand All @@ -30,24 +29,20 @@ def __init__(self, msg, file_context):
SALVEException.__init__(self, msg, file_context=file_context)


class Block(with_metaclass(abc.ABCMeta, AbstractBlock)):
class CoreBlock(with_metaclass(abc.ABCMeta, Block)):
"""
A block is the basic unit of configuration.
Typically, blocks describe files, SALVE manifests, patches, etc
This is an ABC that defines the common characteristics of all
blocks.
blocks in the SALVE Core.
"""
# these are the valid types of block, and therefore the valid
# block identifiers (case insensitive)
types = Enum('FILE', 'MANIFEST', 'DIRECTORY')

def __init__(self, ty, file_context):
"""
Base Block constructor.
Base CoreBlock constructor.
Args:
@ty
An element of Block.types, the type of the block.
An element of CoreBlock.types, the type of the block.
@file_context
The FileContext of this Block. Used to pass globals and
Expand Down
12 changes: 5 additions & 7 deletions salve/block/directory_block.py
Expand Up @@ -5,15 +5,13 @@
import salve

from salve import action
from salve.action import backup
from salve.action import copy
from salve.action import create
from salve.action import modify
from salve.action import backup, copy, create, modify

from salve.block import Block, BlockException
from salve.api import Block
from salve.block import CoreBlock, BlockException


class DirBlock(Block):
class DirBlock(CoreBlock):
"""
A directory block describes an action performed on a directory.
This includes creation, deletion, and copying from source.
Expand All @@ -26,7 +24,7 @@ def __init__(self, file_context):
@file_context
The FileContext for this block.
"""
Block.__init__(self, Block.types.DIRECTORY, file_context)
CoreBlock.__init__(self, Block.types.DIRECTORY, file_context)
for attr in ['target', 'source']:
self.path_attrs.add(attr)
for attr in ['target']:
Expand Down
12 changes: 5 additions & 7 deletions salve/block/file_block.py
Expand Up @@ -5,15 +5,13 @@
import salve

from salve import action
from salve.action import backup
from salve.action import copy
from salve.action import create
from salve.action import modify
from salve.action import backup, copy, create, modify

from salve.block import Block, BlockException
from salve.api import Block
from salve.block import CoreBlock, BlockException


class FileBlock(Block):
class FileBlock(CoreBlock):
"""
A file block describes an action performed on a file.
This includes creation, deletion, and string append.
Expand All @@ -26,7 +24,7 @@ def __init__(self, file_context):
@file_context
The FileContext for this block.
"""
Block.__init__(self, Block.types.FILE, file_context)
CoreBlock.__init__(self, Block.types.FILE, file_context)
for attr in ['target', 'source']:
self.path_attrs.add(attr)
for attr in ['target']:
Expand Down
10 changes: 4 additions & 6 deletions salve/block/identifier.py
Expand Up @@ -5,15 +5,13 @@
from salve.reader.tokenize import Token

from salve.block import BlockException
import salve.block.file_block
import salve.block.manifest_block
import salve.block.directory_block
from salve.block import file_block, manifest_block, directory_block

# maps valid identifiers to block constructors
identifier_map = {
'file': salve.block.file_block.FileBlock,
'manifest': salve.block.manifest_block.ManifestBlock,
'directory': salve.block.directory_block.DirBlock
'file': file_block.FileBlock,
'manifest': manifest_block.ManifestBlock,
'directory': directory_block.DirBlock
}


Expand Down
7 changes: 4 additions & 3 deletions salve/block/manifest_block.py
Expand Up @@ -6,10 +6,11 @@
from salve import action

from salve.util.context import ExecutionContext
from salve.block import Block
from salve.api import Block
from salve.block import CoreBlock


class ManifestBlock(Block):
class ManifestBlock(CoreBlock):
"""
A manifest block describes another manifest to be expanded and
executed. It may also specify properties of that manifest's
Expand All @@ -31,7 +32,7 @@ def __init__(self, file_context, source=None):
# transition to the parsing/block expansion phase, converting
# files into blocks
salve.exec_context.transition(ExecutionContext.phases.PARSING)
Block.__init__(self, Block.types.MANIFEST, file_context)
CoreBlock.__init__(self, Block.types.MANIFEST, file_context)
self.sub_blocks = None
if source:
self.set('source', source)
Expand Down

0 comments on commit d6d2dae

Please sign in to comment.