Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used git clone instead to download source from a branch of a tag #832

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean_up has been removed entirely and it's not used anywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was a default parameter, which was never used

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git is always in the PATH, right? Is there a check for this somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a check somewhere else in the script that git is actually installed and in the PATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to be a sample script, which assumes Git is in the path. FYI please check README .

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