Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De namespace #27

Merged
merged 2 commits into from
Jan 23, 2023
Merged
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
2 changes: 1 addition & 1 deletion NOTES.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ $ python setup.py test

OR

$ python -e 'import Ska.ftp; Ska.ftp.test()'
$ python -e 'import ska_ftp; ska_ftp.test()'
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Ska.ftp documentation build configuration file, created by
# ska_ftp documentation build configuration file, created by
# sphinx-quickstart on Tue May 19 15:46:11 2020.
#
# This file is execfile()d with the current directory set to its
Expand All @@ -20,7 +20,7 @@
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
from Ska.ftp import __version__
from ska_ftp import __version__

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -49,7 +49,7 @@
master_doc = 'index'

# General information about the project.
project = 'Ska.ftp'
project = 'ska_ftp'
copyright = '2020, Tom Aldcroft'
author = 'Tom Aldcroft'

Expand Down Expand Up @@ -89,8 +89,8 @@
html_theme = 'bootstrap-ska'
html_theme_options = {
'logotext1': 'Ska! ', # white, semi-bold
'logotext2': 'Ska', # orange, light
'logotext3': '.ftp', # white, light
'logotext2': 'ska_ftp', # orange, light
'logotext3': '', # white, light
'homepage_url': 'https://cxc.cfa.harvard.edu/mta/ASPECT/tool_doc',
'homepage_text': 'ska',
'homepage_text_2': 'tools'
Expand Down Expand Up @@ -153,7 +153,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Skaftp.tex', 'Ska.ftp Documentation',
(master_doc, 'Skaftp.tex', 'ska_ftp Documentation',
'Tom Aldcroft', 'manual'),
]

Expand All @@ -163,7 +163,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'chandratime', 'Ska.ftp Documentation',
(master_doc, 'chandratime', 'ska_ftp Documentation',
[author], 1)
]

Expand All @@ -174,7 +174,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Skaftp', 'Ska.ftp Documentation',
(master_doc, 'Skaftp', 'ska_ftp Documentation',
author, 'Skaftp', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
:mod:`Ska.ftp`
:mod:`ska_ftp`
======================

.. automodule:: Ska.ftp.ftp
.. automodule:: ska_ftp.ftp

Example
----------
::

import os
import Ska.ftp
import ska_ftp

lucky = Ska.ftp.FTP('lucky')
lucky = ska_ftp.FTP('lucky')

lucky.cd('/taldcroft')
print lucky.ls()
Expand Down
24 changes: 17 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from setuptools import setup
from ska_helpers.setup_helper import duplicate_package_info
from testr.setup_helper import cmdclass

try:
from testr.setup_helper import cmdclass
except ImportError:
cmdclass = {}
name = "ska_ftp"
namespace = "Ska.ftp"

setup(name='Ska.ftp',
packages = ["ska_ftp", "ska_ftp.tests"]
package_dir = {name: name}
package_data = {"ska_ftp.tests": ["netrc"]}

duplicate_package_info(packages, name, namespace)
duplicate_package_info(package_dir, name, namespace)
duplicate_package_info(package_data, name, namespace)


setup(name=name,
author='Tom Aldcroft',
description='Light wrapper around Python ftplib and paramiko.SFTPClient',
author_email='taldcroft@cfa.harvard.edu',
url='http://cxc.harvard.edu/mta/ASPECT/tool_doc/pydocs/Ska.ftp.html',
use_scm_version=True,
setup_requires=['setuptools_scm', 'setuptools_scm_git_archive'],
zip_safe=False,
packages=['Ska', 'Ska.ftp', 'Ska.ftp.tests'],
package_data={'Ska.ftp.tests': ['netrc']},
packages=packages,
package_data=package_data,
package_dir=package_dir,
tests_require=['pytest'],
cmdclass=cmdclass,
)
2 changes: 1 addition & 1 deletion Ska/ftp/__init__.py → ska_ftp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .ftp import *

__version__ = ska_helpers.get_version('Ska.ftp')
__version__ = ska_helpers.get_version('ska_ftp')


def test(*args, **kwargs):
Expand Down
36 changes: 18 additions & 18 deletions Ska/ftp/ftp.py → ska_ftp/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, host, user=None, passwd=None, netrcfile=None, logger=None):

self.logger = logger
if self.logger:
self.logger.info('Ska.ftp: log in to {} as {}'.format(host, user))
self.logger.info('ska_ftp: log in to {} as {}'.format(host, user))

def __del__(self):
"""
Expand All @@ -104,7 +104,7 @@ def cd(self, dirname):
:param dirname: directory name
"""
if self.logger:
self.logger.info('Ska.ftp: cd {}'.format(dirname))
self.logger.info('ska_ftp: cd {}'.format(dirname))
self.ftp.chdir(dirname)

def ls(self, dirname='.'):
Expand All @@ -114,7 +114,7 @@ def ls(self, dirname='.'):
:returns: list of file and/or directory names
"""
if self.logger:
self.logger.info('Ska.ftp: ls {}'.format(dirname))
self.logger.info('ska_ftp: ls {}'.format(dirname))
return self.ftp.listdir(dirname)

def ls_full(self, dirname='.'):
Expand All @@ -124,7 +124,7 @@ def ls_full(self, dirname='.'):
:returns: list of full FTP output for LIST command
"""
if self.logger:
self.logger.info('Ska.ftp: ls {}'.format(dirname))
self.logger.info('ska_ftp: ls {}'.format(dirname))
return [x.longname for x in self.ftp.listdir_attr(dirname)]

def put(self, localfile, remotefile=None, callback=None, confirm=True):
Expand All @@ -138,7 +138,7 @@ def put(self, localfile, remotefile=None, callback=None, confirm=True):
if remotefile is None:
remotefile = os.path.basename(localfile)
if self.logger:
self.logger.info('Ska.ftp: put {} as {}'.format(localfile, remotefile))
self.logger.info('ska_ftp: put {} as {}'.format(localfile, remotefile))
self.ftp.put(localfile, remotefile, callback=callback, confirm=confirm)

def get(self, remotefile, localfile=None, callback=None):
Expand All @@ -150,7 +150,7 @@ def get(self, remotefile, localfile=None, callback=None):
if localfile is None:
localfile = os.path.basename(remotefile)
if self.logger:
self.logger.info('Ska.ftp: get {} as {}'.format(remotefile, localfile))
self.logger.info('ska_ftp: get {} as {}'.format(remotefile, localfile))
self.ftp.get(remotefile, localfile, callback=callback)

def mkdir(self, remotedir):
Expand All @@ -159,7 +159,7 @@ def mkdir(self, remotedir):
:param remotedir: dir name on remote FTP host
"""
if self.logger:
self.logger.info('Ska.ftp: mkdir {}'.format(remotedir))
self.logger.info('ska_ftp: mkdir {}'.format(remotedir))
self.ftp.mkdir(remotedir)

def rename(self, oldpath, newpath):
Expand All @@ -169,7 +169,7 @@ def rename(self, oldpath, newpath):
:param newpath: new path on remote
"""
if self.logger:
self.logger.info('Ska.ftp: rename {} {}'.format(oldpath, newpath))
self.logger.info('ska_ftp: rename {} {}'.format(oldpath, newpath))
self.ftp.rename(oldpath, newpath)

def delete(self, path):
Expand All @@ -178,7 +178,7 @@ def delete(self, path):
:param path: path on remote to delete
"""
if self.logger:
self.logger.info('Ska.ftp: delete {}'.format(path))
self.logger.info('ska_ftp: delete {}'.format(path))
self.ftp.remove(path)

def rmdir(self, path):
Expand All @@ -187,18 +187,18 @@ def rmdir(self, path):
:param path: path on remote to delete
"""
if self.logger:
self.logger.info('Ska.ftp: rmdir {}'.format(path))
self.logger.info('ska_ftp: rmdir {}'.format(path))
self.ftp.rmdir(path)

def __getattr__(self, attr):
"""
Fall through to SFTPClient methods, and fail if not found.
"""
if (attr == 'ftp') or (attr == 'logger'):
raise AttributeError("'{}' attr missing from Ska.ftp object".format(attr))
raise AttributeError("'{}' attr missing from ska_ftp object".format(attr))
val = getattr(self.ftp, attr)
if self.logger:
self.logger.info('Ska.ftp: {}'.format(attr))
self.logger.info('ska_ftp: {}'.format(attr))
return val


Expand Down Expand Up @@ -232,15 +232,15 @@ def __init__(self, host, user=None, passwd=None, netrcfile=None, logger=None):
self.ftp = self # for back compatibility with initial release
self.logger = logger
if self.logger:
self.logger.info('Ska.ftp: log in to {} as {}'.format(host, user))
self.logger.info('ska_ftp: log in to {} as {}'.format(host, user))

def cd(self, dirname):
"""Change to specified directory ``dirname``.

:param dirname: directory name
"""
if self.logger:
self.logger.info('Ska.ftp: cd {}'.format(dirname))
self.logger.info('ska_ftp: cd {}'.format(dirname))
self.cwd(dirname)

def ls(self, dirname='', *args):
Expand All @@ -250,7 +250,7 @@ def ls(self, dirname='', *args):
:returns: list of file and/or directory names
"""
if self.logger:
self.logger.info('Ska.ftp: ls {} {}'.format(dirname, ' '.join(str(x) for x in args)))
self.logger.info('ska_ftp: ls {} {}'.format(dirname, ' '.join(str(x) for x in args)))
return self.nlst(dirname, *args)

def ls_full(self, dirname='', *args):
Expand All @@ -260,7 +260,7 @@ def ls_full(self, dirname='', *args):
:returns: list of full FTP output for LIST command
"""
if self.logger:
self.logger.info('Ska.ftp: ls {} {}'.format(dirname, ' '.join(str(x) for x in args)))
self.logger.info('ska_ftp: ls {} {}'.format(dirname, ' '.join(str(x) for x in args)))
return self.dir(dirname, *args)

def put(self, localfile, remotefile=None):
Expand All @@ -272,7 +272,7 @@ def put(self, localfile, remotefile=None):
if remotefile is None:
remotefile = os.path.basename(localfile)
if self.logger:
self.logger.info('Ska.ftp: put {} as {}'.format(localfile, remotefile))
self.logger.info('ska_ftp: put {} as {}'.format(localfile, remotefile))
with contextlib.closing(open(localfile, 'rb')) as fh:
self.storbinary('STOR ' + remotefile, fh)

Expand All @@ -285,6 +285,6 @@ def get(self, remotefile, localfile=None):
if localfile is None:
localfile = os.path.basename(remotefile)
if self.logger:
self.logger.info('Ska.ftp: get {} as {}'.format(remotefile, localfile))
self.logger.info('ska_ftp: get {} as {}'.format(remotefile, localfile))
with contextlib.closing(open(localfile, 'wb')) as fh:
self.retrbinary('RETR ' + remotefile, fh.write)
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions Ska/ftp/tests/test_basic.py → ska_ftp/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import os
import random
from pathlib import Path
import Ska.ftp
import ska_ftp
import tempfile
import pyyaks.logger
import pytest

logger = pyyaks.logger.get_logger()

NETRC = Ska.ftp.parse_netrc()
NETRC = ska_ftp.parse_netrc()
LUCKY = 'lucky.cfa.harvard.edu'


def roundtrip(FtpClass, logger=None):
user = NETRC[LUCKY]['login']
homedir = ('/home/' if FtpClass is Ska.ftp.SFTP else '/') + user
homedir = ('/home/' if FtpClass is ska_ftp.SFTP else '/') + user
lucky = FtpClass(LUCKY, logger=logger)
lucky.cd(homedir)
files_before = lucky.ls()
Expand All @@ -43,19 +43,19 @@ def roundtrip(FtpClass, logger=None):


def test_roundtrip():
# roundtrip(FtpClass=Ska.ftp.FTP, logger=logger) # legacy of non-secure ftp
roundtrip(FtpClass=Ska.ftp.SFTP, logger=logger)
# roundtrip(FtpClass=ska_ftp.FTP, logger=logger) # legacy of non-secure ftp
roundtrip(FtpClass=ska_ftp.SFTP, logger=logger)


def test_roundtrip_no_logger():
# roundtrip(FtpClass=Ska.ftp.FTP)
roundtrip(FtpClass=Ska.ftp.SFTP)
# roundtrip(FtpClass=ska_ftp.FTP)
roundtrip(FtpClass=ska_ftp.SFTP)


def test_sftp_mkdir_rmdir_rename():
user = NETRC[LUCKY]['login']
homedir = '/home/{}'.format(user)
lucky = Ska.ftp.SFTP(LUCKY, logger=logger)
lucky = ska_ftp.SFTP(LUCKY, logger=logger)
lucky.cd(homedir)

tmpdir = str(uuid.uuid4()) # random remote dir name
Expand All @@ -76,9 +76,9 @@ def test_sftp_mkdir_rmdir_rename():

def test_delete_when_ftp_session_already_gone(capfd):
"""
Confirm that Ska.ftp does not throw attribute errors when deleted.
Confirm that ska_ftp does not throw attribute errors when deleted.
"""
lucky = Ska.ftp.SFTP(LUCKY, logger=logger)
lucky = ska_ftp.SFTP(LUCKY, logger=logger)
# Delete the paramiko session (without explicitly closing in this test case)
del lucky.ftp
del lucky
Expand All @@ -89,7 +89,7 @@ def test_delete_when_ftp_session_already_gone(capfd):

def test_parse_netrc():
cwd = os.path.dirname(__file__)
netrc = Ska.ftp.parse_netrc(os.path.join(cwd, 'netrc'))
netrc = ska_ftp.parse_netrc(os.path.join(cwd, 'netrc'))
assert netrc == {'test1': {'account': None,
'login': 'test1_login',
'password': 'test1_password'},
Expand All @@ -100,9 +100,9 @@ def test_parse_netrc():

def test_parse_netrc_fail():
with pytest.raises(IOError):
Ska.ftp.parse_netrc('does not exist')
ska_ftp.parse_netrc('does not exist')


def test_no_user_no_passwd():
with pytest.raises(ValueError, match='must provide both user and passwd'):
Ska.ftp.SFTP('--host-not-in-netrc--')
ska_ftp.SFTP('--host-not-in-netrc--')