1
+ #!/usr/bin/env python
2
+
3
+ # --------------------------------------------------------------------------------------------
4
+ # Copyright (c) Microsoft Corporation. All rights reserved.
5
+ # Licensed under the MIT License. See License.txt in the project root for license information.
6
+ # --------------------------------------------------------------------------------------------
7
+
8
+ from __future__ import print_function
9
+ import os
10
+ import re
11
+ import sys
12
+ import tempfile
13
+ import utility
14
+ from azure .storage .blob import BlockBlobService , ContentSettings
15
+
16
+ AZURE_STORAGE_CONNECTION_STRING = os .environ .get ('AZURE_STORAGE_CONNECTION_STRING' )
17
+ BLOB_CONTAINER_NAME = 'simple'
18
+ UPLOADED_PACKAGE_LINKS = []
19
+
20
+
21
+ def print_heading (heading , f = None ):
22
+ print ('{0}\n {1}\n {0}' .format ('=' * len (heading ), heading ), file = f )
23
+
24
+
25
+ def upload_index_file (service , blob_name , title , links ):
26
+ print ('Uploading index file {}' .format (blob_name ))
27
+ service .create_blob_from_text (
28
+ container_name = BLOB_CONTAINER_NAME ,
29
+ blob_name = blob_name ,
30
+ text = "<html><head><title>{0}</title></head><body><h1>{0}</h1>{1}</body></html>"
31
+ .format (title , '\n ' .join (
32
+ ['<a href="{0}">{0}</a><br/>' .format (link ) for link in links ])),
33
+ content_settings = ContentSettings (
34
+ content_type = 'text/html' ,
35
+ content_disposition = None ,
36
+ content_encoding = None ,
37
+ content_language = None ,
38
+ content_md5 = None ,
39
+ cache_control = None
40
+ )
41
+ )
42
+
43
+
44
+ def gen_pkg_index_html (service , pkg_name ):
45
+ links = []
46
+ index_file_name = pkg_name + '/'
47
+ for blob in list (service .list_blobs (BLOB_CONTAINER_NAME , prefix = index_file_name )):
48
+ if blob .name == index_file_name :
49
+ # Exclude the index file from being added to the list
50
+ continue
51
+ links .append (blob .name .replace (index_file_name , '' ))
52
+ upload_index_file (service , index_file_name , 'Links for {}' .format (pkg_name ), links )
53
+ UPLOADED_PACKAGE_LINKS .append (index_file_name )
54
+
55
+
56
+ def upload_package (service , file_path , pkg_name ):
57
+ print ('Uploading {}' .format (file_path ))
58
+ file_name = os .path .basename (file_path )
59
+ blob_name = '{}/{}' .format (pkg_name , file_name )
60
+ service .create_blob_from_path (
61
+ container_name = BLOB_CONTAINER_NAME ,
62
+ blob_name = blob_name ,
63
+ file_path = file_path
64
+ )
65
+ gen_pkg_index_html (service , pkg_name )
66
+
67
+
68
+ def build (options ):
69
+
70
+ supported_actions = ['nightly' ]
71
+ action = None
72
+
73
+ if len (options ) >= 1 :
74
+ if options [0 ] not in supported_actions :
75
+ print ('Please provide a supported action {}.' .format (supported_actions ))
76
+ return
77
+ action = options [0 ]
78
+
79
+ if action == 'nightly' :
80
+ assert AZURE_STORAGE_CONNECTION_STRING , 'Set AZURE_STORAGE_CONNECTION_STRING environment variable'
81
+
82
+ print_heading ('Cleanup' )
83
+
84
+ # clean
85
+ utility .clean_up (utility .MSSQLSCRIPTER_DIST_DIRECTORY )
86
+ utility .clean_up (utility .MSSQLTOOLSSERVICE_DIST_DIRECTORY )
87
+ utility .cleaun_up_egg_info_sub_directories (utility .ROOT_DIR )
88
+ utility .cleaun_up_egg_info_sub_directories (utility .MSSQLTOOLSSERVICE_DIRECTORY )
89
+
90
+ print_heading ('Running setup' )
91
+
92
+ # install general requirements.
93
+ utility .exec_command ('pip install -r dev_requirements.txt' , utility .ROOT_DIR )
94
+
95
+ print_heading ('Running mssql-scripter tests' )
96
+ utility .exec_command ('tox' , utility .ROOT_DIR , continue_on_error = False )
97
+
98
+ print_heading ('Building mssql-scripter pip package' )
99
+ utility .exec_command ('python setup.py check -r -s sdist' , utility .ROOT_DIR , continue_on_error = False )
100
+
101
+ print_heading ('Building mssqltoolsservice pip package' )
102
+ utility .exec_command ('python buildwheels.py' , utility .MSSQLTOOLSSERVICE_DIRECTORY , continue_on_error = False )
103
+
104
+ if action == 'nightly' :
105
+ blob_service = BlockBlobService (connection_string = AZURE_STORAGE_CONNECTION_STRING )
106
+
107
+ print_heading ('Uploading packages to blob storage ' )
108
+ for pkg in os .listdir (utility .MSSQLSCRIPTER_DIST_DIRECTORY ):
109
+ pkg_path = os .path .join (utility .MSSQLSCRIPTER_DIST_DIRECTORY , pkg )
110
+ print ('Uploading package {}' .format (pkg_path ))
111
+ upload_package (blob_service , pkg_path , 'mssql-scripter' )
112
+
113
+ for pkg in os .listdir (utility .MSSQLTOOLSSERVICE_DIST_DIRECTORY ):
114
+ pkg_path = os .path .join (utility .MSSQLTOOLSSERVICE_DIST_DIRECTORY , pkg )
115
+ pkg_name = os .path .basename (pkg_path ).split ('-' )[0 ].replace ('_' , '-' ).lower ()
116
+ print ('Uploading package {}' .format (pkg_name ))
117
+ upload_package (blob_service , pkg_path , pkg_name )
118
+
119
+ # Upload the final index file
120
+ upload_index_file (blob_service , 'index.html' , 'Simple Index' , UPLOADED_PACKAGE_LINKS )
121
+
122
+
123
+ if __name__ == '__main__' :
124
+ build (sys .argv [1 :])
0 commit comments