Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ numpy
pandas
paramiko
pyparsing
pytz
yapf
4 changes: 0 additions & 4 deletions xun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

from . import fs
from . import serialization
from .core import ExportError
from .core import SchemaError
from .core import args_hash
from .core import filename_from_args
from .functions import ComputeError
from .functions import CopyError
from .functions import Function
Expand Down
33 changes: 33 additions & 0 deletions xun/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
"""
from pathlib import Path
from textwrap import dedent
import argparse
import sys

Expand Down Expand Up @@ -53,6 +54,38 @@ def main(args=None):
parser_fgraph_action.add_argument('--dot', action='store_true')


#
# XunFS
#
try:
from .fs import cli as fs
parser_mnt = subparsers.add_parser('mount', description=dedent('''\
arguments after a bare -- are forwarded to fuse as is. The fuse
argument for mountpoint is required.

Example
-------
xun mount -s disk /path/to/store -q '() => ...' -- /mnt/pnt
'''), formatter_class=argparse.RawTextHelpFormatter)
parser_mnt.set_defaults(func=fs.main)
parser_mnt_store = parser_mnt.add_mutually_exclusive_group(required=True)
parser_mnt_store.add_argument('-s', '--store',
nargs='+',
action=fs.StoreAction)
parser_mnt_store.add_argument('--store-pickle',
type=fs.store_pickle,
dest='store')
parser_mnt_query = parser_mnt.add_mutually_exclusive_group(required=True)
parser_mnt_query.add_argument('-q', '--query',
nargs='+',
action=fs.QueryAction)
parser_mnt_query.add_argument('--query-file',
type=fs.query_file,
dest='query')
parser_mnt.add_argument('fuse_args', nargs=argparse.REMAINDER)
except NotImplementedError:
pass

#
# create new project from cookiecutter template
#
Expand Down
55 changes: 0 additions & 55 deletions xun/core.py

This file was deleted.

9 changes: 9 additions & 0 deletions xun/fs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
from . import queries

try:
from .filesystem import mount
except NotImplementedError:
pass
fuse_available = False
else:
from . import cli
fuse_available = True
45 changes: 45 additions & 0 deletions xun/fs/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse
import base64
import pickle


def main(args):
from .filesystem import fuse, Fuse, XunFS
server = XunFS(args.store,
args.query,
usage="XunFS\n" + Fuse.fusage,
version="%prog " + fuse.__version__)
fuse_args = list(args.fuse_args)[1:] # Strip -- from previous parse
fuse_args.append('-f') # Run in foreground
server.parse(fuse_args)
server.main()


class StoreAction(argparse.Action):
class StoreConstructors:
@staticmethod
def disk(path):
from ..functions.store import Disk
return Disk(path, create_dirs=False)

def __call__(self, parser, namespace, values, option_string=None):
store_name, *args = values
try:
store = getattr(StoreAction.StoreConstructors, store_name)(*args)
setattr(namespace, self.dest, store)
except Exception as e:
parser.error(f'Invalid store ({store_name}) arguments ({args})')


class QueryAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, ' '.join(values))


def store_pickle(s):
return pickle.loads(base64.urlsafe_b64decode(s.encode()))


def query_file(filename):
with open(filename, 'r') as f:
return f.read()
Loading