-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.py
41 lines (36 loc) · 1.37 KB
/
publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
2019-02-05
author: qbin
"""
import os
import mimetypes
import zipfile
import datetime
import json
import sys
from azure.storage.blob import BlockBlobService
from azure.storage.blob import PublicAccess
from azure.storage.blob import ContentSettings
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
from win32api import GetFileVersionInfo, LOWORD, HIWORD
with open('publish.key.json') as f:
data = json.load(f)
storage_name = data['storage_name']
storage_account_key = data['storage_account_key']
block_blob_service = BlockBlobService(account_name=storage_name, account_key=storage_account_key)
table_service = TableService(account_name=storage_name, account_key=storage_account_key)
def upload(blob_path, file_path):
block_blob_service.create_blob_from_path('static',
blob_path,
file_path,
content_settings=ContentSettings(content_type=mimetypes.guess_type(file_path)[0]))
## upload js, css, etc...
prefix_name = 'home'
asset_folder_path = os.getcwd() + '\\dist'
for root, dirs, files in os.walk(asset_folder_path, topdown=False):
for name in files:
relative_path = root.replace(asset_folder_path, '').replace('\\', '/') + '/' + name
full_path = root + '\\' + name
print('upload: {0}'.format(relative_path))
upload(relative_path, prefix_name + relative_path, full_path)