# Path: nasman/snapshots/utils/base.py
# class BaseUtil(metaclass=abc.ABCMeta):
#     timezone_name = get_default_timezone_name()
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `BaseFilesystem` objects
#         :rtype: list
#         """
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_snapshots(cls):
#         """
#         Gets a list of snapshots
#         :return: A list of `BaseSnapshot`
#         :rtype: list
#         """
# 
# class BaseFilesystem(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, mountpoint=''):
#         self._name = name
#         self._mountpoint = mountpoint
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the filesystem
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def mountpoint(self):
#         """
#         :return: The mountpoint of the filesystem
#         :rtype: basestring
#         """
# 
# class BaseSnapshot(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, timestamp=None, filesystem=None):
#         self._name = name
#         self._filesystem = filesystem
#         if timestamp is not None:
#             self._timestamp = timestamp
#         else:
#             self._timestamp = now()
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the snapshot
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def timestamp(self):
#         """
#         :return: The creation time of this snapshot
#         :rtype: `datetime.datetime`
#         """
# 
#     @property
#     @abc.abstractmethod
#     def filesystem(self):
#         """
#         :return: The parent filesystem of this snapshot
#         :rtype: `BaseFilesystem`
#         """


from datetime import datetime
from subprocess import check_output, CalledProcessError, STDOUT
from pathlib import Path
from django.core.cache import cache
from .base import BaseUtil, BaseFilesystem, BaseSnapshot
import logging
import pytz




logger = logging.getLogger(__name__)


def _parse_cmd_output(cmd):
    """
    Run the given arguments as a subprocess, and spilt the output into lines
    and columns
    :param cmd: The command arguments to run
    :type cmd: list
    :return: The parsed output
    :rtype: list
    """
    try:
        output = check_output(cmd, stderr=STDOUT)
    except CalledProcessError as e:
        logger.error('Failed to pass command %s', ' '.join(cmd))
        logger.error('Output was %s', e.output)
        raise
    return [x.split() for x in output.decode('utf-8').splitlines()]



# Path: nasman/snapshots/utils/base.py
# class BaseUtil(metaclass=abc.ABCMeta):
#     timezone_name = get_default_timezone_name()
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `BaseFilesystem` objects
#         :rtype: list
#         """
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_snapshots(cls):
#         """
#         Gets a list of snapshots
#         :return: A list of `BaseSnapshot`
#         :rtype: list
#         """
# 
# class BaseFilesystem(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, mountpoint=''):
#         self._name = name
#         self._mountpoint = mountpoint
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the filesystem
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def mountpoint(self):
#         """
#         :return: The mountpoint of the filesystem
#         :rtype: basestring
#         """
# 
# class BaseSnapshot(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, timestamp=None, filesystem=None):
#         self._name = name
#         self._filesystem = filesystem
#         if timestamp is not None:
#             self._timestamp = timestamp
#         else:
#             self._timestamp = now()
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the snapshot
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def timestamp(self):
#         """
#         :return: The creation time of this snapshot
#         :rtype: `datetime.datetime`
#         """
# 
#     @property
#     @abc.abstractmethod
#     def filesystem(self):
#         """
#         :return: The parent filesystem of this snapshot
#         :rtype: `BaseFilesystem`
#         """


# Path: nasman/snapshots/utils/zfs.py
from datetime import datetime
from subprocess import check_output, CalledProcessError, STDOUT
from pathlib import Path
from django.core.cache import cache
from .base import BaseUtil, BaseFilesystem, BaseSnapshot
import logging
import pytz





logger = logging.getLogger(__name__)


def _parse_cmd_output(cmd):
    """
    Run the given arguments as a subprocess, and spilt the output into lines
    and columns
    :param cmd: The command arguments to run
    :type cmd: list
    :return: The parsed output
    :rtype: list
    """
    try:
        output = check_output(cmd, stderr=STDOUT)
    except CalledProcessError as e:
        logger.error('Failed to pass command %s', ' '.join(cmd))
        logger.error('Output was %s', e.output)
        raise
    return [x.split() for x in output.decode('utf-8').splitlines()]



class ZFSSnapshot(BaseSnapshot):