#NEWLINE# def main( ) : #NEWLINE# #INDENT# version = '' #NEWLINE# with open ( 'files/version.txt' ) as f : #NEWLINE# #INDENT# version = f . read ( ) . strip ( ) #NEWLINE# #UNINDENT# base_url = 'https://api.github.com/repos/jyapayne/Web2Executable/releases' #NEWLINE# req = requests . get ( ( ( base_url + '/tags/' ) + version ) ) #NEWLINE# update = False #NEWLINE# rel_id = None #NEWLINE# upload_url = None #NEWLINE# github_user = input ( 'Github user:' ) #NEWLINE# password = getpass . getpass ( 'Password:' ) #NEWLINE# if ( req . status_code == 200 ) : #NEWLINE# #INDENT# print ( 'Found release:' , version ) #NEWLINE# json_data = json . loads ( req . text ) #NEWLINE# tag = json_data . get ( 'tag_name' , '' ) #NEWLINE# cur_ver = Version ( tag [ 1 : ( - 1 ) ] ) #NEWLINE# new_ver = Version ( version [ 1 : ( - 1 ) ] ) #NEWLINE# if ( new_ver <= cur_ver ) : #NEWLINE# #INDENT# update = True #NEWLINE# rel_id = json_data [ 'id' ] #NEWLINE# upload_url = json_data [ 'upload_url' ] . replace ( '{?name,label}' , '' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not update ) : #NEWLINE# #INDENT# print ( 'Creating release:' , version ) #NEWLINE# data = { #NEWLINE# #INDENT# 'tag_name' : version , #NEWLINE# 'target_commitish' : 'master' , #NEWLINE# 'name' : ( 'Web2Executable ' + version ) , #NEWLINE# #UNINDENT# } #NEWLINE# post_res = requests . post ( base_url , data = json . dumps ( data ) , auth = ( github_user , password ) ) #NEWLINE# if ( post_res . status_code == 201 ) : #NEWLINE# #INDENT# json_data = json . loads ( post_res . text ) #NEWLINE# upload_url = json_data [ 'upload_url' ] . replace ( '{?name,label}' , '' ) #NEWLINE# rel_id = json_data [ 'id' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Authentication failed!' ) #NEWLINE# #UNINDENT# #UNINDENT# if rel_id : #NEWLINE# #INDENT# zip_files = glob ( '*.zip' ) #NEWLINE# for zip_file in zip_files : #NEWLINE# #INDENT# with open ( zip_file , 'rb' ) as zipf : #NEWLINE# #INDENT# file_data = zipf . read ( ) #NEWLINE# print ( 'Uploading file {}...' . format ( zip_file ) ) #NEWLINE# data = { #NEWLINE# #INDENT# 'name' : zip_file , #NEWLINE# #UNINDENT# } #NEWLINE# headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/zip' , #NEWLINE# #UNINDENT# } #NEWLINE# r = requests . post ( upload_url , params = data , data = file_data , headers = headers , auth = ( github_user , password ) ) #NEWLINE# if ( r . status_code == 201 ) : #NEWLINE# #INDENT# print ( 'Success!' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Error:' , r . text )