Use HTTP to upload to work around Travis issues
This commit is contained in:
		
							parent
							
								
									e0fa36efc8
								
							
						
					
					
						commit
						6634c9b5d2
					
				
							
								
								
									
										43
									
								
								upload.py
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								upload.py
									
									
									
									
									
								
							@ -2,7 +2,11 @@ import re, os, sys
 | 
				
			|||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import zipfile
 | 
					import zipfile
 | 
				
			||||||
import ftplib
 | 
					import base64
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
						import urllib.request as urllib
 | 
				
			||||||
 | 
					except ImportError:
 | 
				
			||||||
 | 
						import urllib2 as urllib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
project = 'accelerator'
 | 
					project = 'accelerator'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -21,13 +25,13 @@ def GITHash():
 | 
				
			|||||||
	return stdout.rstrip('\r\n')
 | 
						return stdout.rstrip('\r\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def GITBranch():
 | 
					def GITBranch():
 | 
				
			||||||
        travis_branch = os.environ.get('TRAVIS_BRANCH', False)
 | 
						travis_branch = os.environ.get('TRAVIS_BRANCH', False)
 | 
				
			||||||
        if travis_branch:
 | 
						if travis_branch:
 | 
				
			||||||
            return travis_branch
 | 
							return travis_branch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        appveyor_branch = os.environ.get('APPVEYOR_REPO_BRANCH', False)
 | 
						appveyor_branch = os.environ.get('APPVEYOR_REPO_BRANCH', False)
 | 
				
			||||||
        if appveyor_branch:
 | 
						if appveyor_branch:
 | 
				
			||||||
            return appveyor_branch
 | 
							return appveyor_branch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
 | 
						p = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
 | 
				
			||||||
	(stdout, stderr) = p.communicate()
 | 
						(stdout, stderr) = p.communicate()
 | 
				
			||||||
@ -77,25 +81,14 @@ for zinfo in zip.infolist():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
zip.close()
 | 
					zip.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if 'ftp_hostname' in os.environ:
 | 
					if 'ftp_username' in os.environ:
 | 
				
			||||||
	print('')
 | 
						print('')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ftp = ftplib.FTP(os.environ['ftp_hostname'], os.environ['ftp_username'], os.environ['ftp_password'])
 | 
						request = urllib.Request("https://builds.limetech.io/upload.php?project=%s&branch=%s&filename=%s" % (project, GITBranch(), filename), open(filename, 'rb'), headers={
 | 
				
			||||||
	print('Connected to server, uploading build...')
 | 
							'Authorization': "Basic %s" % (base64.encodestring(("%s:%s" % (os.environ['ftp_username'], os.environ['ftp_password'])).encode()).decode()[:-1]),
 | 
				
			||||||
	ftp.cwd(os.environ['ftp_directory'])
 | 
							'Content-Type': 'application/zip',
 | 
				
			||||||
 | 
					    	'Content-Length': os.stat(filename).st_size,
 | 
				
			||||||
        branch = GITBranch()
 | 
						})
 | 
				
			||||||
        if branch != 'master':
 | 
						print(urllib.urlopen(request).read().decode('utf-8'))
 | 
				
			||||||
            ftp.cwd('branch')
 | 
					 | 
				
			||||||
            branch = project + '-' + branch
 | 
					 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                ftp.mkd(branch)
 | 
					 | 
				
			||||||
            except:
 | 
					 | 
				
			||||||
                pass
 | 
					 | 
				
			||||||
            ftp.cwd(branch)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	print(ftp.storbinary('STOR ' + filename, open(filename, 'rb')))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ftp.quit()
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	print('Uploaded as \'' + filename + '\'')
 | 
						print('Uploaded as \'' + filename + '\'')
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user