def LoadSettings(self): """ Load the ini file and set all options. """ configParser = ConfigParser.ConfigParser() if not IsCIBuild(): configParser.read(self._configFilePath) for task in self.buildSetup.tasks: section = task.GetId() if not configParser.has_section(section): continue options = configParser.options(section) for option in options: if option == "enabled": if task.visible: task.activated = eval( configParser.get(section, "enabled")) else: task.options[option] = configParser.get(section, option) #print section, option, configParser.get(section, option) if configParser.has_option("GitHub", "Repository"): repository = configParser.get('GitHub', "Repository") try: user, repo = repository.split('/') except ValueError: user = repo = "" self.buildSetup.gitConfig.update({ "user": user, "repo": repo, "branch": configParser.get('GitHub', "Branch") })
def __init__(self): if not VirtualEnv.Running() and VirtualEnv.Exists(): VirtualEnv.Activate() global buildSetup Task.buildSetup = self buildSetup = self self.pyVersionStr = "%d%d" % sys.version_info[:2] self.buildDir = abspath(join(dirname(__file__), "..")) self.sourceDir = abspath(join(self.buildDir, "..")) self.libraryName = "lib%s" % self.pyVersionStr self.libraryDir = join(self.sourceDir, self.libraryName) self.dataDir = join(self.buildDir, "data") self.docsDir = join(self.dataDir, "docs") self.pyVersionDir = join(self.dataDir, "Python%s" % self.pyVersionStr) self.outputDir = join(self.buildDir, "output") self.websiteDir = join(self.outputDir, "website") if Is64bitInterpreter(): print( "ERROR: Sorry, EventGhost can't be built with the 64-bit " "version of Python!" ) sys.exit(1) elif not exists(self.pyVersionDir): print( "ERROR: Sorry, EventGhost can't be built with Python %d.%d!" % sys.version_info[:2] ) sys.exit(1) sys.path.append(self.sourceDir) sys.path.append(join(self.libraryDir, "site-packages")) self.args = self.ParseArgs() self.showGui = not ( self.args.build or self.args.check or self.args.package or self.args.release or self.args.sync ) if os.environ.get( "APPVEYOR_REPO_COMMIT_MESSAGE", "" ).upper().startswith("VERBOSE:"): self.args.verbose = True os.chdir(self.buildDir) if not exists(self.outputDir): os.mkdir(self.outputDir) LogToFile(join(self.outputDir, "Build.log"), self.args.verbose) from CheckDependencies import CheckDependencies if not CheckDependencies(self): sys.exit(1) try: self.gitConfig = GetGitHubConfig() except Exception as e: msg = ( "WARNING: To change version or release to GitHub, you must:\n" " $ git config --global github.user <your github username>\n" " $ git config --global github.token <your github token>\n" "To create a token, go to: https://github.com/settings/tokens\n" ) if type(e) is ValueError: msg = "WARNING: Specified `github.token` is invalid!\n" + msg if not IsCIBuild(): token = "" print msg else: token = os.environ["GITHUB_TOKEN"] self.gitConfig = { "all_repos": { "EventGhost/EventGhost": { "all_branches": ["master"], "def_branch": "master", "name": "EventGhost", }, }, "branch": "master", "repo": "EventGhost", "repo_full": "EventGhost/EventGhost", "token": token, "user": "******", } self.appVersion = None self.appVersionInfo = None self.tmpDir = tempfile.mkdtemp() self.appName = self.name
def DoTask(self): buildSetup = self.buildSetup appVer = "v" + buildSetup.appVersion gitConfig = buildSetup.gitConfig token = gitConfig["token"] user = gitConfig["user"] repo = gitConfig["repo"] branch = gitConfig["branch"] setupFile = 'EventGhost_{0}_Setup.exe'.format(buildSetup.appVersion) setupPath = join(buildSetup.outputDir, setupFile) self.chglogFile = "CHANGELOG.md" self.chglogShort = "CHANGELOG_THIS_RELEASE.md" chglogPath = join(buildSetup.outputDir, self.chglogFile) print "reading changelog" try: f = open(chglogPath, 'r') except IOError: print "ERROR: couldn't read changelog file ({0}).".format( self.chglogFile) return else: changelog = f.read() f.close() print "loading installer file" try: f = open(setupPath, 'rb') except IOError: print "ERROR: '{0}' not found.".format(setupFile) return else: setupFileContent = f.read() f.close() gh = GitHub(token=token) # delete a temporary tag that were used to deploy a release if IsCIBuild(): # when we are on CI, we only get here, # when a deploy tag was created self.DeleteDeployTag(gh) branch = gitConfig["branch"] = 'master' print "getting release info" releaseExists = False releaseId = None uploadUrl = None page = 1 while page > 0: rc, data = gh.repos[user][repo].releases.get(sha=branch, per_page=100, page=page) page = NextPage(gh) if rc == 200: for rel in data: if rel['name'] == appVer: msg = ("Found an existing GitHub release matching" " '{0}'".format(appVer)) if IsCIBuild(): raise BuildError(msg) app = wx.GetApp() win = app.GetTopWindow() dlg = wx.MessageDialog(win, caption="Information", message=msg + "\nOverwrite it?", style=wx.YES_NO) if dlg.ShowModal() == wx.ID_NO: return releaseId = rel["id"] uploadUrl = str(rel['upload_url'][:-13]) releaseExists = True page = 0 break print "getting branch info" rc, data = gh.repos[user][repo].branches[branch].get() if rc != 200: raise BuildError("ERROR: couldn't get branch info.") commitSha = data['commit']['sha'] # if not uploadUrl: # uploadUrl = str(data['upload_url'][:-13]) rc, data = gh.repos[user][repo].contents[self.chglogFile].get( ref=branch) if rc == 200: remoteChangelog = base64.decodestring(data["content"]) else: remoteChangelog = None newCommitSha = None if changelog != remoteChangelog: newCommitSha = self.CommitChangelog(gh, commitSha, changelog) if not releaseExists: print "reading changelog for this release" try: f = open(join(buildSetup.outputDir, self.chglogShort), 'r') except IOError: print "ERROR: couldn't read changelog file ({0}).".format( self.chglogShort) relChglog = "" else: relChglog = f.read().strip() f.close() print "creating release" body = dict(tag_name=appVer, target_commitish=newCommitSha, name=appVer, body=relChglog, draft=False, prerelease=("-" in self.buildSetup.appVersion)) rc, data = gh.repos[user][repo].releases.post(body=body) if rc != 201: raise BuildError("ERROR: couldn't create a release on GitHub.") uploadUrl = str(data['upload_url'][:-13]) else: print 'deleting existing asset' rc, data = gh.repos[user][repo].releases[releaseId].assets.get() if rc == 200: for asset in data: if asset["name"] == setupFile: rc, data = gh.repos[user][repo].releases.\ assets[asset["id"]].delete() if rc != 204: print "ERROR: couldn't delete existing asset." return break print "uploading setup file" url = uploadUrl + '?name={0}'.format(setupFile) headers = { 'content-type': 'application/octet-stream', 'authorization': 'Token {0}'.format(token), 'accept': 'application/vnd.github.v3+json', 'user-agent': 'agithub/v2.0' } conn = http.client.HTTPSConnection('uploads.github.com') conn.request('POST', url, setupFileContent, headers) response = conn.getresponse() status = response.status conn.close() if status != 201: raise BuildError( "ERROR: couldn't upload installer file to GitHub.")