1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024 |
- from azure_storage.methods import arg_dict_cleanup, create_batch_dict, create_parent_parser, parse_batch_file, \
- setup_arguments
- from azure_storage.azure_upload import AzureUpload
- from azure_storage.azure_sas import AzureContainerSAS, AzureSAS
- from azure_storage.azure_move import AzureContainerMove, AzureMove
- from azure_storage.azure_download import AzureContainerDownload, AzureDownload
- from azure_storage.azure_tier import AzureContainerTier, AzureTier
- from azure_storage.azure_delete import AzureContainerDelete, AzureDelete
- from argparse import ArgumentParser, RawTextHelpFormatter
- import coloredlogs
- import logging
- import sys
- import os
- def file_upload(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureUpload class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'file', 'reset_path', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
-
- try:
-
- upload_file = AzureUpload(
- object_name=arg_dict['file'],
- account_name=args.account_name,
- container_name=arg_dict['container'],
- passphrase=args.passphrase,
- path=arg_dict['reset_path'],
- storage_tier=arg_dict['storage_tier'],
- category='file'
- )
-
- upload_file.main()
-
- except SystemExit:
- pass
- def folder_upload(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureUpload class for each folder
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'folder', 'reset_path', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- upload_folder = AzureUpload(
- object_name=arg_dict['folder'],
- account_name=args.account_name,
- container_name=arg_dict['container'],
- passphrase=args.passphrase,
- path=arg_dict['reset_path'],
- storage_tier=arg_dict['storage_tier'],
- category='folder'
- )
-
- upload_folder.main()
-
- except SystemExit:
- pass
- def container_sas(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureSAS class for each container
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'expiry', 'output_file'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- sas_container = AzureContainerSAS(
- container_name=arg_dict['container'],
- output_file=arg_dict['output_file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- expiry=arg_dict['expiry'],
- verbosity=args.verbosity
- )
-
- sas_container.main()
-
- except SystemExit:
- pass
- def file_sas(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureSAS class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'file', 'expiry', 'output_file'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- sas_file = AzureSAS(
- object_name=arg_dict['file'],
- container_name=arg_dict['container'],
- output_file=arg_dict['output_file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- expiry=arg_dict['expiry'],
- verbosity=args.verbosity,
- category='file',
- )
-
- sas_file.main()
-
- except SystemExit:
- pass
- def folder_sas(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureSAS class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'folder', 'expiry', 'output_file'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- sas_folder = AzureSAS(
- object_name=arg_dict['folder'],
- container_name=arg_dict['container'],
- output_file=arg_dict['output_file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- expiry=arg_dict['expiry'],
- verbosity=args.verbosity,
- category='folder',
- )
-
- sas_folder.main()
-
- except SystemExit:
- pass
- def container_move(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureContainerMove class
- for each container
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'target', 'reset_path', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- move_container = AzureContainerMove(
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- target_container=arg_dict['target'],
- path=arg_dict['reset_path'],
- storage_tier=arg_dict['storage_tier']
- )
-
- move_container.main()
-
- except SystemExit:
- pass
- def file_move(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureMove class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'target', 'file', 'reset_path', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- move_file = AzureMove(
- object_name=arg_dict['file'],
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- target_container=arg_dict['target'],
- path=arg_dict['reset_path'],
- storage_tier=arg_dict['storage_tier'],
- category='file'
- )
-
- move_file.main()
-
- except SystemExit:
- pass
- def folder_move(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments to work with code base, run the AzureMove class for each folder
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'target', 'folder', 'reset_path', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- move_folder = AzureMove(
- object_name=arg_dict['folder'],
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- target_container=arg_dict['target'],
- path=arg_dict['reset_path'],
- storage_tier=arg_dict['storage_tier'],
- category='folder'
- )
-
- move_folder.main()
-
- except SystemExit:
- pass
- def container_download(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureContainerDownload class for each container
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'output_path'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- download_container = AzureContainerDownload(
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- output_path=arg_dict['output_path']
- )
-
- download_container.main()
-
- except SystemExit:
- pass
- def file_download(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureDownload class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'file', 'output_path'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- download_file = AzureDownload(
- container_name=arg_dict['container'],
- object_name=arg_dict['file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- output_path=arg_dict['output_path'],
- category='file'
- )
-
- download_file.main()
-
- except SystemExit:
- pass
- def folder_download(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureDownload class for each folder
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'folder', 'output_path'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- download_folder = AzureDownload(
- container_name=arg_dict['container'],
- object_name=arg_dict['folder'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- output_path=arg_dict['output_path'],
- category='folder'
- )
-
- download_folder.main()
-
- except SystemExit:
- pass
- def container_tier(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureContainerTier class for each container
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- tier_container = AzureContainerTier(
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- storage_tier=arg_dict['storage_tier']
- )
-
- tier_container.main()
-
- except SystemExit:
- pass
- def file_tier(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureTier class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'file', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- tier_file = AzureTier(
- container_name=arg_dict['container'],
- object_name=arg_dict['file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- storage_tier=arg_dict['storage_tier'],
- category='file'
- )
-
- tier_file.main()
-
- except SystemExit:
- pass
- def folder_tier(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureTier class for each folder
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'folder', 'storage_tier'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- tier_folder = AzureTier(
- container_name=arg_dict['container'],
- object_name=arg_dict['folder'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- storage_tier=arg_dict['storage_tier'],
- category='folder'
- )
-
- tier_folder.main()
-
- except SystemExit:
- pass
- def container_delete(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureContainerDelete class for each container
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- delete_container = AzureContainerDelete(
- container_name=arg_dict['container'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- )
-
- delete_container.main()
-
- except SystemExit:
- pass
- def file_delete(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureDelete class for each file
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'file', 'retention_time'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- delete_file = AzureDelete(
- container_name=arg_dict['container'],
- object_name=arg_dict['file'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- retention_time=arg_dict['retention_time'],
- category='file'
- )
-
- delete_file.main()
-
- except SystemExit:
- pass
- def folder_delete(args, batch_dict=None):
- """
- Read in the batch file, clean up the arguments, run the AzureDelete class for each folder
- :param args: type ArgumentParser arguments
- :param batch_dict: type Pandas dataframe.transpose().to_dict()
- """
-
- if not batch_dict:
- batch_dict = create_batch_dict(batch_file=args.batch_file,
- headers=['container', 'folder', 'retention_time'])
-
-
- for key, arg_dict in batch_dict.items():
-
- arg_dict = arg_dict_cleanup(arg_dict=arg_dict)
- try:
-
- delete_folder = AzureDelete(
- container_name=arg_dict['container'],
- object_name=arg_dict['folder'],
- account_name=args.account_name,
- passphrase=args.passphrase,
- retention_time=arg_dict['retention_time'],
- category='folder'
- )
-
- delete_folder.main()
-
- except SystemExit:
- pass
- def batch(args):
- """
- Read in the batch file, and run the appropriate function for each requested command and subcommand combination
- :param args: type ArgumentParser arguments
- """
-
- try:
- assert os.path.isfile(args.batch_file)
- except AssertionError:
- logging.error(f'Could not locate the supplied batch file {args.batch_file}. Please ensure the you entered '
- f'the name and path correctly')
- raise SystemExit
-
- function_dict = {
- 'upload': {
- 'file': file_upload,
- 'folder': folder_upload
- },
- 'sas': {
- 'container': container_sas,
- 'file': file_sas,
- 'folder': folder_sas
- },
- 'move': {
- 'container': container_move,
- 'file': file_move,
- 'folder': folder_move
- },
- 'download': {
- 'container': container_download,
- 'file': file_download,
- 'folder': folder_download
- },
- 'tier': {
- 'container': container_tier,
- 'file': file_tier,
- 'folder': folder_tier
- },
- 'delete': {
- 'container': container_delete,
- 'file': file_delete,
- 'folder': folder_delete
- }
- }
-
- with open(args.batch_file, 'r') as batch_doc:
- for line in batch_doc:
-
- if not line.startswith('#'):
-
-
- command, subcommand, batch_dict = parse_batch_file(line=line)
-
- function_dict[command][subcommand](args, batch_dict=batch_dict)
- def cli():
- parser = ArgumentParser(
- description='Automate the submission of multiple AzureStorage commands'
- )
-
- subparsers, parent_parser = create_parent_parser(
- parser=parser,
- container=False
- )
-
- upload = subparsers.add_parser(
- parents=[],
- name='upload',
- description='Upload files/folders to Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Upload files/folders to Azure storage'
- )
-
- upload_subparsers = upload.add_subparsers(
- title='Upload functionality',
- dest='upload'
- )
-
- upload_file_subparser = upload_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Upload files to Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Upload files to Azure storage'
- )
- upload_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, file name, destination path (optional), storage tier (optional)'
- )
- upload_file_subparser.set_defaults(func=file_upload)
-
- upload_folder_subparser = upload_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Upload folders to Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Upload folders to Azure storage'
- )
- upload_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields (one entry per line):\n '
- 'container name, folder name, destination path (optional), storage tier (optional)'
- )
- upload_folder_subparser.set_defaults(func=folder_upload)
-
- sas_urls = subparsers.add_parser(
- parents=[],
- name='sas',
- description='Create SAS URLs for containers/files/folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Create SAS URLs for containers/files/folders in Azure storage')
- sas_url_subparsers = sas_urls.add_subparsers(
- title='SAS URL creation functionality',
- dest='sas'
- )
-
- sas_url_container_subparser = sas_url_subparsers.add_parser(
- parents=[parent_parser],
- name='container',
- description='Create SAS URLs for containers in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Create SAS URLs for containers in Azure storage'
- )
- sas_url_container_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields: \n'
- 'container name, expiry (optional), output file (optional)'
- )
- sas_url_container_subparser.set_defaults(func=container_sas)
-
- sas_url_file_subparser = sas_url_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Create SAS URLs for files in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Create SAS URLs for files in Azure storage'
- )
- sas_url_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, file name and path, expiry (optional), output file (optional)'
- )
- sas_url_file_subparser.set_defaults(func=file_sas)
-
- sas_url_folder_subparser = sas_url_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Create SAS URLs for folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Create SAS URLs for folders in Azure storage'
- )
- sas_url_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, folder name and path, expiry (optional), output file (optional)'
- )
- sas_url_folder_subparser.set_defaults(func=folder_sas)
-
- move = subparsers.add_parser(
- parents=[],
- name='move',
- description='Move containers/files/folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Move containers/files/folders in Azure storage'
- )
- move_subparsers = move.add_subparsers(
- title='Move functionality',
- dest='move'
- )
-
- move_container_subparser = move_subparsers.add_parser(
- parents=[parent_parser],
- name='container',
- description='Move containers in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Move containers in Azure storage'
- )
- move_container_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, target container, destination path (optional), storage tier (optional)'
- )
- move_container_subparser.set_defaults(func=container_move)
-
- move_file_subparser = move_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Move files in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Move files in Azure storage'
- )
- move_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, target container, file name, destination path (optional), storage tier (optional)'
- )
- move_file_subparser.set_defaults(func=file_move)
-
- move_folder_subparser = move_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Move folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Move folders in Azure storage'
- )
- move_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, target container, folder name, destination path (optional), storage tier (optional)'
- )
- move_folder_subparser.set_defaults(func=folder_move)
-
- download = subparsers.add_parser(
- parents=[],
- name='download',
- description='Download containers/files/folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Download containers/files/folders in Azure storage'
- )
- download_subparsers = download.add_subparsers(
- title='Download functionality',
- dest='download'
- )
-
- download_container_subparser = download_subparsers.add_parser(
- parents=[parent_parser],
- name='container',
- description='Download containers from Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Download containers from Azure storage'
- )
- download_container_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, output path (optional)'
- )
- download_container_subparser.set_defaults(func=container_download)
-
- download_file_subparser = download_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Download files from Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Download files from Azure storage'
- )
- download_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, file name, output path (optional)'
- )
- download_file_subparser.set_defaults(func=file_download)
-
- download_folder_subparser = download_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Download folders from Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Download folders from Azure storage'
- )
- download_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, folder name, output path (optional)'
- )
- download_folder_subparser.set_defaults(func=folder_download)
-
- tier = subparsers.add_parser(
- parents=[],
- name='tier',
- description='Set the storage tier of containers/files/folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Set the storage tier of containers/files/folders in Azure storage'
- )
- tier_subparsers = tier.add_subparsers(
- title='Storage tier setting functionality',
- dest='tier'
- )
-
- tier_container_subparser = tier_subparsers.add_parser(
- parents=[parent_parser],
- name='container',
- description='Set the storage tier of containers in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Set the storage tier of containers in Azure storage'
- )
- tier_container_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, storage tier'
- )
- tier_container_subparser.set_defaults(func=container_tier)
-
- tier_file_subparser = tier_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Set the storage tier of files in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Set the storage tier of files in Azure storage'
- )
- tier_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, file name, storage tier'
- )
- tier_file_subparser.set_defaults(func=file_tier)
-
- tier_folder_subparser = tier_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Set the storage tier of folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Set the storage tier of folders in Azure storage'
- )
- tier_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, folder name, storage tier'
- )
- tier_folder_subparser.set_defaults(func=folder_tier)
-
- delete = subparsers.add_parser(
- parents=[],
- name='delete',
- description='Delete containers/files/folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Delete containers/files/folders in Azure storage'
- )
- delete_subparsers = delete.add_subparsers(
- title='Delete functionality',
- dest='delete'
- )
-
- delete_container_subparser = delete_subparsers.add_parser(
- parents=[parent_parser],
- name='container',
- description='Delete containers in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Delete containers in Azure storage'
- )
- delete_container_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='File with the following field:\n '
- 'container name'
- )
- delete_container_subparser.set_defaults(func=container_delete)
-
- delete_file_subparser = delete_subparsers.add_parser(
- parents=[parent_parser],
- name='file',
- description='Delete files in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Delete files in Azure storage'
- )
- delete_file_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, file name, retention time (optional)'
- )
- delete_file_subparser.set_defaults(func=file_delete)
-
- delete_folder_subparser = delete_subparsers.add_parser(
- parents=[parent_parser],
- name='folder',
- description='Delete folders in Azure storage',
- formatter_class=RawTextHelpFormatter,
- help='Delete folders in Azure storage'
- )
- delete_folder_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file with the following fields:\n '
- 'container name, folder name, retention time (optional)'
- )
- delete_folder_subparser.set_defaults(func=folder_delete)
-
- batch_subparser = subparsers.add_parser(
- parents=[parent_parser],
- name='batch',
- description='Perform multiple different operations in batch',
- formatter_class=RawTextHelpFormatter,
- help='Perform multiple different operations in batch'
- )
- batch_subparser.add_argument(
- '-b', '--batch_file',
- required=True,
- type=str,
- help='Tab-separated file in the following format:\n'
- 'command, sub-command, arguments\n\n'
- 'Below is the complete list of functionalities:\n'
- 'upload, file, container name, file name, destination path (optional), storage tier (optional)\n'
- 'upload, folder, container name, folder name, destination path (optional), storage tier (optional)\n'
- 'sas, container, container name, expiry (optional), output file (optional)\n'
- 'sas, file, container name, file name and path, expiry (optional), output file (optional)\n'
- 'sas, folder, container name, folder name and path, expiry (optional), output file (optional)\n'
- 'move, container, container name, target container, destination path (optional), storage tier (optional)\n'
- 'move, file, container name, target container, file name, destination path (optional), '
- 'storage tier (optional)\n'
- 'move, folder, container name, target container, folder name, destination path (optional), '
- 'storage tier (optional)\n'
- 'download, container, container name, output path (optional)\n'
- 'download, file, container name, file name, output path (optional)\n'
- 'download, folder, container name, folder name, output path (optional)\n'
- 'tier, container, container name, storage tier\n'
- 'tier, file, container name, file name, storage tier\n'
- 'tier, folder, container name, folder name, storage tier\n'
- 'delete, container, container name\n'
- 'delete, file, container name, file name, retention time (optional)\n'
- 'delete, folder, container name, folder name, retention time (optional)'
- )
- batch_subparser.set_defaults(func=batch)
-
- arguments = setup_arguments(parser=parser)
-
-
- coloredlogs.install(level=arguments.verbosity.upper())
- logging.info('Operations complete')
-
- sys.stderr = open(os.devnull, 'w')
- return arguments
- if __name__ == '__main__':
- cli()
|