-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removed CLI to move to a separate package * removed remote_dir from Client attributes
- Loading branch information
1 parent
eb99b4f
commit b474603
Showing
12 changed files
with
96 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,3 @@ | ||
# File Retriever | ||
|
||
A tool to connect to and interact with servers via FTP/SFTP clients. | ||
|
||
### Usage | ||
The file_retriever tool can be imported and used in other applications or used with its CLI. | ||
|
||
#### Commands | ||
The following information is also available using `fetch --help` | ||
|
||
##### Get Vendor Files | ||
Retrieves files from one or more vendor servers via FTP/SFTP | ||
|
||
`$ fetch vendor-files` | ||
|
||
Options: | ||
|
||
+ `-v, --vendor` | ||
|
||
+ The vendor whose server you would like to connect to and retrieve files from. | ||
Use `-v all` to retrieve files from all configured vendors. | ||
This option can be repeated: | ||
eg. `$ fetch vendor-files -v eastview -v leila` | ||
|
||
+ `-d, --days` | ||
|
||
+ The number of days to go back to search for files | ||
|
||
+ `-h, --hours` | ||
|
||
+ The number of hours to go back to search for files | ||
|
||
+ `-m, --minutes` | ||
|
||
+ The number of minutes to go back to search for files | ||
|
||
##### Get Daily Vendor Files | ||
Retrieves files updated within last day from servers of all configured vendors | ||
|
||
`$ fetch daily-vendor-files` | ||
|
||
##### Get List of Configured Vendors | ||
Lists all vendors whose servers are available to connect to | ||
|
||
`$ fetch available-vendors` | ||
A tool to connect to and interact with servers via FTP/SFTP clients. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +0,0 @@ | ||
import logging | ||
import logging.config | ||
import os | ||
import click | ||
from file_retriever.utils import client_config, logger_config, get_recent_files | ||
|
||
logger = logging.getLogger("file_retriever") | ||
|
||
|
||
@click.group() | ||
@click.pass_context | ||
def file_retriever_cli(ctx: click.Context) -> None: | ||
""" | ||
CLI for interacting with remote servers. | ||
Loggers are configured when the command group is called. The `client_config` | ||
function is used to read a configuration file with credentials and set the | ||
creds as environment variables. `client_config` returns a list of names for | ||
servers whose credentials are stored in the configuration file and loaded | ||
to env vars. This list of names is stored in a `click.Context.obj` that can | ||
be passed to any other commands. | ||
""" | ||
config = logger_config() | ||
logging.config.dictConfig(config) | ||
ctx.obj = client_config( | ||
os.path.join(os.environ["USERPROFILE"], ".cred/.sftp/connections.yaml") | ||
) | ||
pass | ||
|
||
|
||
@file_retriever_cli.command( | ||
"vendor-files", short_help="Retrieve files from remote server." | ||
) | ||
@click.option( | ||
"--vendor", | ||
"-v", | ||
"vendor", | ||
type=str, | ||
multiple=True, | ||
help="Vendor to retrieve files for.", | ||
) | ||
@click.option( | ||
"--days", | ||
"-d", | ||
"days", | ||
default=0, | ||
type=int, | ||
help="How many days back to retrieve files.", | ||
) | ||
@click.option( | ||
"--hours", | ||
"-h", | ||
"hours", | ||
default=0, | ||
type=int, | ||
help="How many hours back to retrieve files.", | ||
) | ||
@click.option( | ||
"--minutes", | ||
"-m", | ||
"minutes", | ||
default=0, | ||
type=int, | ||
help="How many minutes back to retrieve files.", | ||
) | ||
@click.pass_context | ||
def get_files( | ||
ctx: click.Context, vendor: str, days: int, hours: int, minutes: int | ||
) -> None: | ||
""" | ||
Retrieve files from remote server for specified vendor(s). | ||
Args: | ||
vendor: | ||
name of vendor to retrieve files from. if 'all' then all vendors | ||
listed in config file will be included, otherwise multiple values | ||
can be passed and each will be added to a list. files will be | ||
retrieved for each vendor in the list | ||
days: | ||
number of days to go back and retrieve files from | ||
hours: | ||
number of hours to go back and retrieve files from | ||
minutes: | ||
number of minutes to go back and retrieve files from | ||
""" | ||
if "all" in vendor and isinstance(ctx.obj, list): | ||
vendor_list = [i.upper() for i in ctx.obj if i != "NSDROP"] | ||
else: | ||
vendor_list = [i.upper() for i in vendor] | ||
get_recent_files(vendors=vendor_list, days=days, hours=hours, minutes=minutes) | ||
|
||
|
||
@file_retriever_cli.command( | ||
"daily-vendor-files", short_help="Retrieve previous day's files from remote server." | ||
) | ||
@click.pass_context | ||
def get_files_today(ctx: click.Context) -> None: | ||
""" | ||
Retrieve files updated within last day from remote server for all vendor(s). | ||
Args: | ||
ctx: click context object that contains a list of vendor names | ||
""" | ||
vendor_list = [i.upper() for i in ctx.obj if i != "NSDROP"] | ||
click.echo(vendor_list) | ||
get_recent_files(vendors=vendor_list, days=1) | ||
|
||
|
||
@file_retriever_cli.command( | ||
"available-vendors", short_help="List all configured vendors." | ||
) | ||
@click.pass_context | ||
def list_config_vendors(ctx: click.Context) -> None: | ||
""" | ||
List all configured vendors. | ||
Args: | ||
ctx: click context object that contains a list of vendor names | ||
""" | ||
if isinstance(ctx.obj, list) and len(ctx.obj) > 0: | ||
click.echo(f"Available vendors: {ctx.obj}") | ||
else: | ||
click.echo("No vendors available.") | ||
|
||
|
||
def main(): | ||
file_retriever_cli() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.