Source

cloudster / api / storages / adapters / skeleton.py

Full commit
import abc
from api.serializers import json_types
from functools import wraps

__accounts_field_registry__ = {}

def account_field(cls,name, label, type):

	def inner(f):

		if cls in __accounts_field_registry__:
			__accounts_field_registry__[cls].append(AccountFieldDescriptor(name, label,type))
		else:
			__accounts_field_registry__[cls]=[AccountFieldDescriptor(name, label,type)]

		def wrapped(*args, **kwargs):
			return f(*args, **kwargs)
		return wraps(f)(wrapped)

	return inner

class StorageAdapter(object):

	__metaclass__ = abc.ABCMeta

	@staticmethod
	@abc.abstractmethod
	def registry_metadata():
		pass

	def __init__(self):
		pass

	@abc.abstractmethod
	def read(self, full_remote_path, target_file_path=None):
		pass

	@abc.abstractmethod
	def write(self, target_full_path, source_file, overwrite=True):
		pass

	@abc.abstractmethod
	def move(self):
		pass

	@abc.abstractmethod
	def list(self, path):
		pass

	@abc.abstractmethod
	def connect(self):
		pass

	@abc.abstractmethod
	def about(self):
		pass

	@abc.abstractmethod
	def remove(self, full_path):
		pass

	@abc.abstractmethod
	def events(self, history_pointer = None):
		pass


class StorageAccountData(json_types.JSonizable):

	def __init__(self):
		pass

	def parse(self,account_data):
		return json_types.JSonizable.fromJSON(self,account_data)

	def save(self,target):
		pass

	@staticmethod
	@abc.abstractmethod
	def get_configuration_fields():
		pass

	@staticmethod
	def _list_account_field(account_id):
		return __accounts_field_registry__[account_id]

	@staticmethod
	@abc.abstractmethod
	def create_descriptor(properties=None,interactive=False):
		pass

class AccountFieldDescriptor():

	FIELD_TYPE_STRING=1

	def __init__(self,name,label=None,type=FIELD_TYPE_STRING):
		self.__name=name
		self.__type=type
		self.__label=label

	def name(self):
		return self.__name

	def label(self):
		if self.__label is None:
			return self.__name

		return self.__label

	def type(self):
		return self.__type

	def __str__(self):
		return '{name: %s, label: %s, type: %i}'% (self.name(), self.label(),self.type())