# Path: nasman/snapshots/models.py
# class File(models.Model):
#     """
#     Model representing a file/directory/etc on the filesystem
#     """
#     snapshot_path = models.TextField(
#         'snapshot path',
#         help_text='The path to the file when the relevant snapshot is mounted')
#     original_path = models.TextField(
#         'original path',
#         help_text='The original path on the filesystem when the snapshot was '
#                   'taken'
#     )
#     snapshot_name = models.TextField(
#         'snapshot name',
#         help_text='Name of the snapshot'
#     )
#     path_encoding = models.TextField(
#         'path encoding',
#         help_text='The filesystem encoding for this file',
#         blank=True
#     )
#     search_index = VectorField()
# 
#     objects = SearchManager(
#         fields=('snapshot_path', 'original_path'),
#         config='pg_catalog.english',
#         search_field='search_index',
#         auto_update_search_field=True
#     )
# 
#     class Meta:
#         app_label = 'snapshots'
# 
# Path: nasman/snapshots/utils/zfs.py
# class ZFSUtil(BaseUtil):
#     """
#     Helper utility for accessing ZFS features
#     """
# 
#     @classmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `ZFSFilesystem` objects
#         :rtype: list
#         """
#         parsed = _parse_cmd_output(
#             ['zfs', 'list', '-Hp', '-tfilesystem', '-oname,mountpoint']
#         )
#         if parsed is None:
#             return None
#         filesystems = []
#         for fs in parsed:
#             filesystems.append(
#                 ZFSFilesystem(
#                     fs[0],
#                     fs[1]
#                 )
#             )
#         return filesystems
# 
#     @classmethod
#     def get_snapshots(cls, refresh=False):
#         """
#         Gets a list of snapshots
#         :return: A list of `ZFSSnapshot`
#         :rtype: list
#         """
#         cached = cache.get('zfs-snapshots')
#         if not refresh and cached is not None:
#             logger.info('Returning cached list')
#             return cached
#         parsed = _parse_cmd_output(
#             ['zfs', 'list', '-Hp', '-tsnap', '-oname,creation']
#         )
#         if parsed is None:
#             return None
#         snaps = []
#         for snap in parsed:
#             ts = datetime.fromtimestamp(int(snap[1]))
#             ts = pytz.timezone(cls.timezone_name).localize(ts)
#             snaps.append(
#                 ZFSSnapshot(
#                     snap[0],
#                     ts
#                 )
#             )
#         cache.set('zfs-snapshots', snaps, 43200)
#         logger.info('Refreshed list of snapshots {}'.format(snaps))
#         return snaps
# 
#     @classmethod
#     def get_filesystem(cls, fs_name):
#         """
#         Gets a filesystem by name
#         :param fs_name: Name of the filesystem to get
#         :type fs_name: basestring
#         :return: A `ZFSFilesystem`
#         :rtype: `nasman.snapshots.zfs.ZFSFilesystem`
#         """
#         parsed = _parse_cmd_output(
#             ['zfs',
#              'list',
#              '-Hp',
#              '-tfilesystem',
#              '-oname,mountpoint',
#              fs_name]
#         )
#         if parsed is None:
#             return None
#         return ZFSFilesystem(parsed[0][0], parsed[0][1])
# 
#     @classmethod
#     def get_snapshot(cls, snap_name):
#         """
#         Gets a snapshot by name
#         :param snap_name: Name of the snapshot to get
#         :type snap_name: basestring
#         :return: A `ZFSSnapshot`
#         :rtype: `nasman.snapshots.zfs.ZFSSnapshot`
#         """
#         parsed = _parse_cmd_output(
#             ['zfs',
#              'list',
#              '-Hp',
#              '-tsnap',
#              '-oname,creation',
#              snap_name]
#         )
#         if parsed is None:
#             return None
#         return ZFSSnapshot(parsed[0][0], parsed[0][1])
# 
#     @classmethod
#     def create_snapshot(cls, snap_name, fs_name, recurse):
#         """
#         Creates a snapshot
#         :param snap_name: Name of the snapshot to create
#         :type snap_name: str
#         :param fs_name: Name of the filesystem to take snapshot of
#         :type fs_name: str
#         :param recurse: Whether to recurse filesystems
#         :type recurse: bool
#         :return: The snapshot just created
#         :rtype: `nasman.snapshots.zfs.ZFSSnapshot`
#         """
#         cache.delete('zfs-snapshots')
#         full_name = '{0}@{1}'.format(
#             fs_name,
#             snap_name
#         )
#         cmd = ['zfs',
#                'snapshot',
#                full_name
#                ]
#         if recurse:
#             cmd.append('-r')
#         parsed = _parse_cmd_output(cmd)
#         if parsed is None:
#             return None
#         return cls.get_snapshot(full_name)
# 
# Path: nasman/snapshots/widgets.py
# class SmallSelectWidget(BootstrapClassesMixin, forms.Select):
#     classes = ['input-sm', 'form-control']
# 
# class BootstrapCheckboxWidget(BootstrapClassesMixin, forms.CheckboxInput):
#     classes = ['checkbox']
# 
# class BootstrapTextWidget(BootstrapClassesMixin, forms.TextInput):
#     pass
# 
# class BootstrapSelectWidget(BootstrapClassesMixin, forms.Select):
#     pass


from pathlib import Path
from .models import File
from .utils.zfs import ZFSUtil
from .widgets import (
    SmallSelectWidget,
    BootstrapCheckboxWidget,
    BootstrapTextWidget,
    BootstrapSelectWidget
)
import floppyforms.__future__ as forms




def filesystem_choices():
    """
    A callable for use by forms that allow choosing a ZFS Filesystem
    :return: The list of ZFS filesystems on the system
    :rtype: tuple
    """

# Path: nasman/snapshots/models.py
# class File(models.Model):
#     """
#     Model representing a file/directory/etc on the filesystem
#     """
#     snapshot_path = models.TextField(
#         'snapshot path',
#         help_text='The path to the file when the relevant snapshot is mounted')
#     original_path = models.TextField(
#         'original path',
#         help_text='The original path on the filesystem when the snapshot was '
#                   'taken'
#     )
#     snapshot_name = models.TextField(
#         'snapshot name',
#         help_text='Name of the snapshot'
#     )
#     path_encoding = models.TextField(
#         'path encoding',
#         help_text='The filesystem encoding for this file',
#         blank=True
#     )
#     search_index = VectorField()
# 
#     objects = SearchManager(
#         fields=('snapshot_path', 'original_path'),
#         config='pg_catalog.english',
#         search_field='search_index',
#         auto_update_search_field=True
#     )
# 
#     class Meta:
#         app_label = 'snapshots'
# 
# Path: nasman/snapshots/utils/zfs.py
# class ZFSUtil(BaseUtil):
#     """
#     Helper utility for accessing ZFS features
#     """
# 
#     @classmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `ZFSFilesystem` objects
#         :rtype: list
#         """
#         parsed = _parse_cmd_output(
#             ['zfs', 'list', '-Hp', '-tfilesystem', '-oname,mountpoint']
#         )
#         if parsed is None:
#             return None
#         filesystems = []
#         for fs in parsed:
#             filesystems.append(
#                 ZFSFilesystem(
#                     fs[0],
#                     fs[1]
#                 )
#             )
#         return filesystems
# 
#     @classmethod
#     def get_snapshots(cls, refresh=False):
#         """
#         Gets a list of snapshots
#         :return: A list of `ZFSSnapshot`
#         :rtype: list
#         """
#         cached = cache.get('zfs-snapshots')
#         if not refresh and cached is not None:
#             logger.info('Returning cached list')
#             return cached
#         parsed = _parse_cmd_output(
#             ['zfs', 'list', '-Hp', '-tsnap', '-oname,creation']
#         )
#         if parsed is None:
#             return None
#         snaps = []
#         for snap in parsed:
#             ts = datetime.fromtimestamp(int(snap[1]))
#             ts = pytz.timezone(cls.timezone_name).localize(ts)
#             snaps.append(
#                 ZFSSnapshot(
#                     snap[0],
#                     ts
#                 )
#             )
#         cache.set('zfs-snapshots', snaps, 43200)
#         logger.info('Refreshed list of snapshots {}'.format(snaps))
#         return snaps
# 
#     @classmethod
#     def get_filesystem(cls, fs_name):
#         """
#         Gets a filesystem by name
#         :param fs_name: Name of the filesystem to get
#         :type fs_name: basestring
#         :return: A `ZFSFilesystem`
#         :rtype: `nasman.snapshots.zfs.ZFSFilesystem`
#         """
#         parsed = _parse_cmd_output(
#             ['zfs',
#              'list',
#              '-Hp',
#              '-tfilesystem',
#              '-oname,mountpoint',
#              fs_name]
#         )
#         if parsed is None:
#             return None
#         return ZFSFilesystem(parsed[0][0], parsed[0][1])
# 
#     @classmethod
#     def get_snapshot(cls, snap_name):
#         """
#         Gets a snapshot by name
#         :param snap_name: Name of the snapshot to get
#         :type snap_name: basestring
#         :return: A `ZFSSnapshot`
#         :rtype: `nasman.snapshots.zfs.ZFSSnapshot`
#         """
#         parsed = _parse_cmd_output(
#             ['zfs',
#              'list',
#              '-Hp',
#              '-tsnap',
#              '-oname,creation',
#              snap_name]
#         )
#         if parsed is None:
#             return None
#         return ZFSSnapshot(parsed[0][0], parsed[0][1])
# 
#     @classmethod
#     def create_snapshot(cls, snap_name, fs_name, recurse):
#         """
#         Creates a snapshot
#         :param snap_name: Name of the snapshot to create
#         :type snap_name: str
#         :param fs_name: Name of the filesystem to take snapshot of
#         :type fs_name: str
#         :param recurse: Whether to recurse filesystems
#         :type recurse: bool
#         :return: The snapshot just created
#         :rtype: `nasman.snapshots.zfs.ZFSSnapshot`
#         """
#         cache.delete('zfs-snapshots')
#         full_name = '{0}@{1}'.format(
#             fs_name,
#             snap_name
#         )
#         cmd = ['zfs',
#                'snapshot',
#                full_name
#                ]
#         if recurse:
#             cmd.append('-r')
#         parsed = _parse_cmd_output(cmd)
#         if parsed is None:
#             return None
#         return cls.get_snapshot(full_name)
# 
# Path: nasman/snapshots/widgets.py
# class SmallSelectWidget(BootstrapClassesMixin, forms.Select):
#     classes = ['input-sm', 'form-control']
# 
# class BootstrapCheckboxWidget(BootstrapClassesMixin, forms.CheckboxInput):
#     classes = ['checkbox']
# 
# class BootstrapTextWidget(BootstrapClassesMixin, forms.TextInput):
#     pass
# 
# class BootstrapSelectWidget(BootstrapClassesMixin, forms.Select):
#     pass


# Path: nasman/snapshots/forms.py
from pathlib import Path
from .models import File
from .utils.zfs import ZFSUtil
from .widgets import (
    SmallSelectWidget,
    BootstrapCheckboxWidget,
    BootstrapTextWidget,
    BootstrapSelectWidget
)
import floppyforms.__future__ as forms





def filesystem_choices():
    """
    A callable for use by forms that allow choosing a ZFS Filesystem
    :return: The list of ZFS filesystems on the system
    :rtype: tuple
    """

    filesystems = [x.name for x in ZFSUtil.get_filesystems()]