from azure.storage.file import FileService
from azure.storage import CloudStorageAccount
from azure.storage.file import ContentSettings
import azure.common
# account_name ='muthuselvan3storage'
# account_key = 'f2J7qn5vNrcfnYedWeK9QLEeWhNtVEjWSV+syakafhJSKyMP2wYVrP5lIZDvv7bwmYmoCQKnVsXfL51Oblte4A=='

account_name ='muthuse'
account_key = 'ziqZHhLftAh5LYBSFwepM88gdc7AZpfuimxYf2ocjfxR8LjEFohV6JmkzAGbqvqOawcgpwCC2R88tZD5FvEbdw=='

account = CloudStorageAccount(account_name, account_key)
file_service = account.create_file_service()

#https://muthuse.file.core.windows.net/jaf-jar/xenframework-1.0.jar
#https://docs.microsoft.com/en-us/azure/storage/storage-python-how-to-use-file-storage
def upload():
    file_service.create_file_from_path(
        'jaf-jar',
        None, # We want to create this blob in the root directory, so we specify None for the directory_name
        'xenframework-1.0.jar', # remote file name
        'xenframework-1.0.jar', # local file name
        content_settings=ContentSettings(content_type='jar'))
  #https://muthuse.file.core.windows.net/jaf-jar/xen-automation-testcode-2.0.jar      
def listfilesinshare():
    generator = file_service.list_directories_and_files('jaf-jar')
    for file_or_dir in generator:
        print(file_or_dir.name)
        # print file_service.get_resource_name(file_or_dir.name)
      
  
def upload1():
    print ("Uplading")
    file_service.create_file_from_path(
        'jaf-jar',
        None, # We want to create this blob in the root directory, so we specify None for the directory_name
        'xenframework-1.0.jar', # remote file name
        'xenframework-1.0.jar', # local file name
        content_settings=ContentSettings(content_type='image/png'))
        
#def getFilePath():
    #file_service.get_file_to_path('jaf-jar', None, 'myfile', 'out-sunset.png')        


def download():
    generator = file_service.list_directories_and_files('jaf-jar')
    for file_or_dir in generator:
        print(file_or_dir.name)

    shares =  file_service.list_shares()
    for share in shares:
        print('  Share name:' + share.name)

    file_service.get_file_to_path(
                'jaf-jar',              # share name
                 None,          # directory path
                'xenframework-1.0.jar',               # source file name
                'azure_local_storage/xenframework-1.0.jar')       # destinatation path with name




if __name__ == '__main__':
    # download()
    # upload1()
    listfilesinshare()



#https://azure-sdk-for-python.readthedocs.io/en/latest/
#https://docs.microsoft.com/en-us/azure/storage/storage-python-how-to-use-file-storage
#generator = file_service.list_directories_and_files('java')
#for file_or_dir in generator:
 #   print(file_or_dir.name)

#https://github.com/Azure-Samples/storage-file-python-getting-started/blob/master/start.py

#https://github.com/Azure-Samples/storage-file-python-getting-started
