Commit 0139bd19 authored by pavan kumar.siligam's avatar pavan kumar.siligam

refactored code. Included setup.py

parent 88c5e031
k202101@mistralpp3.1023:1550567731
\ No newline at end of file
# -*- coding: utf-8 -*-
from .pypftp import Pftp, upload, download
# cli.py
'''command line interface to HPSS'''
import os
import re
import click
@click.group()
def main():
'command line interface to HPSS'
@main.command()
@click.option('-l', default=False, is_flag=True, help="long listing")
@click.argument('path')
def ls(path, l):
"""List directory contents on tape.
\b
PATH: path on tape
"""
with Pftp() as p:
long_listing = True if l else False
contents = p.listdir(path, long_listing=long_listing)
for line in contents:
click.echo(line)
return
@main.command()
@click.argument('path')
def exists(path):
"""check if PATH exists on tape.
\b
PATH: path on tape
"""
with Pftp() as p:
if not p.exists(path):
click.echo('False')
else:
click.echo('True')
@main.command()
@click.option('-h', is_flag=True, help='human readable format')
@click.argument('path')
def size(path, h):
"""Prints file size in bytes. Use -h option for human readable format.
\b
PATH: path on tape
"""
with Pftp() as p:
if not p.exists(path):
click.echo('File not found')
else:
fsize = p.size(path)
if h:
fsize = sizeof_fmt(fsize)
click.echo("{}".format(fsize))
@main.command()
@click.argument('path')
def mkdir(path):
"""creates PATH on tape.
\b
PATH: path on tape
"""
with Pftp() as p:
if p.exists(path):
click.echo('Already exists')
else:
p.makedirs(path)
@main.command()
@click.argument('path')
def isdir(path):
"""checks if PATH is a directory.
\b
PATH: path on tape
"""
with Pftp() as p:
if not p.exists(path):
click.echo('path not found')
elif p.isdir(path):
click.echo('True')
else:
click.echo('False')
@main.command()
@click.argument('path')
def isfile(path):
"""checks if PATH is a file.
\b
PATH: path on tape
"""
res = 1
with Pftp() as p:
if not p.exists(path):
click.echo('path not found')
elif p.isfile(path):
click.echo('True')
res = 0
else:
click.echo('False')
sys.exit(res)
@main.command()
@click.argument('path')
def islink(path):
"""checks if PATH is a link.
\b
PATH: path on tape
"""
with Pftp() as p:
if not p.exists(path):
click.echo('path not found')
elif p.islink(path):
click.echo('True')
else:
click.echo('False')
This diff is collapsed.
# utils.py
import re
wildcard_check = re.compile('[*?[]')
def has_wildcard(path):
return wildcard_check.search(path) is not None
def human_readable_size(num, suffix='B'):
for unit in ('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi'):
if abs(num) < 1024.0:
return "%3.1f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f %s%s" % (num, 'Yi', suffix)
from setuptools import setup
import os
readme_filename = os.path.join(os.path.dirname(__file__), "README.md")
with open(readme_filename) as f:
readme = f.read()
setup(
name="pypftp",
version="0.1",
description="Python interface to HPSS",
author="Pavan Siligam",
author_email="siligam@dkrz.de",
long_description=readme,
py_modules=["pypftp"],
install_requires=[
"click",
],
entry_points="""
[console_scripts]
pypftp=pypftp.cli:main
""",
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment