Skip to content

Commit

Permalink
Used git clone instead to download source from a branch of a tag (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam authored Aug 17, 2018
1 parent 28a7860 commit 4452a4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
4 changes: 2 additions & 2 deletions buildscripts/builddrivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def validate_input(question, values):
parser.add_argument('--DRIVER', default='all', choices=['all', 'sqlsrv', 'pdo_sqlsrv'], help="driver to build (default: all)")
parser.add_argument('--DEBUG', action='store_true', help="enable debug mode (default: False)")
parser.add_argument('--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)")
parser.add_argument('--BRANCH', default='dev', help="GitHub repository branch (default: dev)")
parser.add_argument('--BRANCH', default='dev', help="GitHub repository branch or tag (default: dev)")
parser.add_argument('--SOURCE', default=None, help="a local path to source file (default: None)")
parser.add_argument('--TESTING', action='store_true', help="turns on testing mode (default: False)")
parser.add_argument('--DESTPATH', default=None, help="an alternative destination for the drivers (default: None)")
Expand Down Expand Up @@ -280,7 +280,7 @@ def validate_input(question, values):
answer = input("Download source from a GitHub repo? [y/n]: ")
if answer == 'yes' or answer == 'y' or answer == '':
repo = input("Name of the repo (hit enter for 'Microsoft'): ")
branch = input("Name of the branch (hit enter for 'dev'): ")
branch = input("Name of the branch or tag (hit enter for 'dev'): ")
if repo == '':
repo = 'Microsoft'
if branch == '':
Expand Down
37 changes: 11 additions & 26 deletions buildscripts/buildtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,48 +193,33 @@ def write_lines_to_copy_source(driver, file):
file.write('@CALL ROBOCOPY ' + source + ' ' + dest + ' /s /xx /xo' + os.linesep)

@staticmethod
def download_msphpsql_source(repo, branch, dest_folder = 'Source', clean_up = True):
def download_msphpsql_source(repo, branch, dest_folder = 'Source'):
"""Download to *dest_folder* the msphpsql archive of the specified
GitHub *repo* and *branch*. The downloaded files will be removed by default.
"""
try:
work_dir = os.path.dirname(os.path.realpath(__file__))

temppath = os.path.join(work_dir, 'temp')
if os.path.exists(temppath):
shutil.rmtree(temppath)
os.makedirs(temppath)
# There is no need to remove tree -
# for Bamboo, it will be cleaned up eventually
# for local development, this can act as a cached copy of the repo
if not os.path.exists(temppath):
os.makedirs(temppath)
os.chdir(temppath)

file = branch + '.zip'
url = 'https://github.com/' + repo + '/msphpsql/archive/' + branch + '.zip'

print('Downloading ' + url + ' ...')
try:
with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
except:
print ("Resort to skip ssl verification...")
# need to skip ssl verification on some agents
# see https://www.python.org/dev/peps/pep-0476/
with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as response, open(file, 'wb') as out_file:
shutil.copyfileobj(response, out_file)

print('Extracting ' + file + ' ...')
zip = zipfile.ZipFile(file)
zip.extractall()
zip.close()

msphpsqlFolder = os.path.join(temppath, 'msphpsql-' + branch)

url = 'https://github.com/' + repo + '/msphpsql.git'
command = 'git clone ' + url + ' -b ' + branch + ' --single-branch --depth 1 ' + msphpsqlFolder
os.system(command)

source = os.path.join(msphpsqlFolder, 'source')
os.chdir(work_dir)

os.system('ROBOCOPY ' + source + '\shared ' + dest_folder + '\shared /xx /xo')
os.system('ROBOCOPY ' + source + '\pdo_sqlsrv ' + dest_folder + '\pdo_sqlsrv /xx /xo')
os.system('ROBOCOPY ' + source + '\sqlsrv ' + dest_folder + '\sqlsrv /xx /xo')

if clean_up:
shutil.rmtree(temppath)

except:
print('Error occurred when downloading source')
Expand Down

0 comments on commit 4452a4d

Please sign in to comment.