def run(stage): heslog.info("Running npm") scriptutil.executeCommand("cd .. && npm install") heslog.warn("This project has no tests to run") return { "env": generateEnv(stage) }
def run(stage): heslog.info("Running yarn") scriptutil.executeCommand("cd ../.. && yarn") heslog.info("Running tests") if not runTests(): return {"error": "Testing Failed"} return {"env": generateEnv(stage)}
def run(stage): heslog.info("Running yarn") scriptutil.executeCommand("cd .. && yarn") heslog.info("Running tests") if not runTests(): return { "error": "Testing Failed" } return { "env": generateEnv(stage) }
def createAsset(self, obj, shouldPublish=False): fields = obj.get("fields", {}) file = fields.get("file", {}).get(LOC_US, None) if file is None: return None title = fields.get("title", {}).get(LOC_US) data = { "fields": { "file": { LOC_US: { "contentType": file.get("contentType"), "upload": file.get("url").replace("//", "http://"), "fileName": file.get("fileName"), } }, "title": { LOC_US: title } } } currentEntry = None # we can't query for assets because "title" is type "Text" and thus we aparently can't use the `=` operator for a in self.allAssets(): existingName = a.get("fields", {}).get("title", {}).get(LOC_US) if existingName == title: currentEntry = a.get("sys", {}) break createdItem = self._createOrUpdate(TYPE_ASSET, data, {}, None, currentEntry, False) if createdItem is None: return None heslog.info("Processing Asset") url = self.baseUrl + "/%s/%s/files/en-US/process" % ( TYPE_ASSET, createdItem.get("id")) headers = { 'Authorization': self.authHeader, 'X-Contentful-Version': createdItem.get("publishedVersion", 1) } response = requests.put(url, headers=headers) return createdItem
def cloneEntries(entries, removeRelated): heslog.info("Cloning %s entries" % len(entries)) skipped = [] for entry, shouldPublish in each(entries): skip = False fromId = entry.get("sys", {}).get("id") heslog.setContext({"objType": "entry", "fromId": fromId}) fields = entry.get("fields", {}) # check if we have all the information for this entry if not removeRelated: for related in fields.get("relatedPages", {}).get(LOC_US, []): if related.get("sys", {}).get("id") not in self._entryMap: skipped.append(entry) skip = True if skip: continue # link the related entries for related in fields.get("relatedPages", {}).get(LOC_US, []): entryId = related["sys"]["id"] related["sys"]["id"] = self._entryMap[entryId] else: heslog.info( "Removing related fields from entry to prevent infinite loop" ) fields["relatedPages"] = {LOC_US: []} # link asset to the one in new space if "image" in fields: assetId = fields["image"][LOC_US]["sys"]["id"] fields["image"][LOC_US]["sys"]["id"] = self._assetMap[ assetId].get("id") sys = self.createEntry(entry, shouldPublish) if sys is None: heslog.warn("Entry %s invliad" % fromId) else: self._entryMap[fromId] = sys.get("id") return skipped
def run(stage, outputs): bucket = None for k, stackInfo in outputs.iteritems(): out = stackInfo.get("outputs", {}) if "BucketName" in out: bucket = out.get("BucketName") break if not bucket: heslog.error("no bucket found to deploy to") return {} heslog.info("Building Source") scriptutil.executeCommand("yarn deploy:prod") heslog.info("Deploying code to bucket %s" % bucket) scriptutil.executeCommand("cd ../dist && aws s3 sync . s3://%s --delete --acl public-read" % bucket) return {}
def _delete(self, objectType, entry): heslog.info("Deleting Object") if entry is None: heslog.error("No Entry") return False objId = entry.get("id") version = entry.get("version", 1) version = str(version) heslog.addContext(objId=objId) headers = {"X-Contentful-Version": version} url = self.baseUrl + ("/%s/%s" % (objectType, objId)) headers.update(self.postHeaders) response = requests.delete(url, headers=headers) if response.text: responseObj = json.loads(response.text) return self._checkSys(responseObj) return True
def query(url, contentType): have = 0 total = 200 data = None while have < total: req = urllib2.Request(url + token + '&skip=%s' % have) try: ret = urllib2.urlopen(req) data = json.loads(ret.read()) total = data.get("total", 0) have += data.get("limit", 200) yield data except urllib2.HTTPError as e: heslog.error("%s" % e.code) heslog.error(e.read()) except urllib2.URLError as e: heslog.error(e.reason) heslog.info("%s had %s entries" % (contentType, total))
def run(stage, outputs): bucket = None for k, stackInfo in outputs.iteritems(): out = stackInfo.get("outputs", {}) if "BucketName" in out: bucket = out.get("BucketName") break if not bucket: heslog.error("no bucket found to deploy to") return {} heslog.info("Build URLS and parameters") scriptutil.executeCommand("cd ../../scripts && yarn install --production") scriptutil.executeCommand( "cd ../../scripts && node buildConfig.js stage=" + stage) heslog.info("Building Source") scriptutil.executeCommand("cd ../.. && yarn install") scriptutil.executeCommand("cd ../.. && yarn build --production") heslog.info("Deploying code to bucket %s" % bucket) scriptutil.executeCommand( "cd ../../build/public && aws s3 sync . s3://%s --delete --acl public-read" % bucket) return {}
def _publish(self, objectType, entry, unpublish=False): action = "Publishing" verb = "PUT" if unpublish: action = "Unpublishing" verb = "DELETE" heslog.info("%s object" % action) if entry is None: heslog.error("No Entry") return None version = entry.get("version", 1) version = str(version) url = self.baseUrl + "/%s/%s/published" % (objectType, entry.get("id")) headers = {"X-Contentful-Version": version} headers.update(self.postHeaders) response = requests.request(verb, url, headers=headers) responseObj = json.loads(response.text) if self._checkSys(responseObj) is None: heslog.info("Failed to publish object") return None sys = responseObj.get("sys", {}) publishedVersion = sys.get("publishedVersion", None) if publishedVersion is not None: heslog.info("Published Version %s" % publishedVersion) return sys
def run(stage, outputs): bucket = None for k, stackInfo in outputs.iteritems(): out = stackInfo.get("outputs", {}) if "BucketName" in out: bucket = out.get("BucketName") break if not bucket: heslog.error("no bucket found to deploy to") return {} heslog.info("Building Source") scriptutil.executeCommand("cd .. && npm run build") heslog.info("Deploying code to bucket %s" % bucket) scriptutil.executeCommand( "cd ../public && aws s3 sync . s3://%s --delete --acl public-read" % bucket) return {}
def printSpace(space): heslog.addContext(space=space.spaceId) heslog.info("ContentTypes") print json.dumps(toSpace.allContentTypes(), indent=2) heslog.info("Assets") print json.dumps(toSpace.allAssets(), indent=2) heslog.info("Entries") print json.dumps(toSpace.allEntries(), indent=2)
def _createOrUpdate(self, objectType, data, extraHeaders, defaultId=None, currentEntry=None, shouldPublish=False): action = "create" if currentEntry is not None: action = "update" heslog.info("Attempting to %s object" % action) headers = extraHeaders or {} url = self.baseUrl + ("/%s" % objectType) if currentEntry is not None: objId = currentEntry.get("id", defaultId) else: objId = defaultId heslog.addContext(objId=objId) verb = "PUT" if objId is None: verb = "POST" else: url += "/%s" % objId if currentEntry is not None: headers.update( {"X-Contentful-Version": currentEntry.get("version", 1)}) headers.update(self.postHeaders) response = requests.request(verb, url, data=json.dumps(data), headers=headers) responseObj = json.loads(response.text) if self._checkSys(responseObj) is None: heslog.info("Failed to %s object" % action) return None sys = responseObj.get("sys", None) heslog.info("%sd Object %s" % (action, sys.get("id"))) if shouldPublish: publishSys = self._publish(objectType, sys) if publishSys is not None: return publishSys return sys
parser.add_argument('--debug', dest="debug", action="store_true") args = parser.parse_args() if args.debug: heslog.setLevels() printOnly = args.printToSpace # or args.printFromSpace timer.start() # fromSpace = Space(args.fromSpace, args.oauthToken) toSpace = Space(args.toSpace, args.oauthToken) if printOnly: if args.printToSpace: printSpace(toSpace) # if args.printFromSpace: # printSpace(fromSpace) # elif args.deleteOnly: # toSpace.deleteDiff(fromSpace) elif args.deleteContent: toSpace.deleteContent() else: print "...please specify a valid task" #toSpace.clone(fromSpace) totalTime = timer.end() heslog.info("Total time: %s Avg Time: %s" % (totalTime, timer.getAvgStep()))
from hesburgh import heslog, hesutil, hestest import json hestest.init(__file__, "testdata") print json.dumps(hestest.get("hbeachey"), indent=2) message = "message" heslog.setContext({"foo": "bar"}) heslog.debug(message, this="that", context="test") heslog.addContext(baz="foo") heslog.addContext({"test": "this"}) heslog.verbose(message) heslog.info(message) heslog.removeContext("baz") heslog.warn(message) heslog.error(message) heslog.setContext({"bar": "baz"}) heslog.info("Setting levels to debug and error") heslog.setLevels(heslog.LEVEL_DEBUG, heslog.LEVEL_ERROR) heslog.debug(message) heslog.verbose(message) # should not print heslog.info(message) # should not print heslog.warn(message) # should not print heslog.error(message) heslog.setContext() ### print types test heslog.debug("Setting all levels")
def run(stage): heslog.info("Retrieving node modules") scriptutil.executeCommand("cd ../backup && yarn install") return { "env": "" }
import urllib2 import json from hesburgh import heslog, hesutil from datetime import datetime if not hesutil.getEnv("TOKEN"): heslog.info("To run this you must source the deploy-env secrets") token = "&access_token=%s" % (hesutil.getEnv("TOKEN", throw=True)) base = "https://cdn.contentful.com/spaces/%s" % hesutil.getEnv("SPACE", throw=True) entryQuery = "/entries?select=%s&limit=200&content_type=%s" now = datetime.now().strftime("%Y-%m-%d") host = "https://library.nd.edu" routeInfo = [ { "route": "", "field": "fields.slug", "type": "page", "exclude": "fields.requiresLogin" }, { "route": "/floor", "field": "fields.slug", "type": "floor", }, { "route": "/news", "field": "fields.slug",