コード例 #1
0
    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
コード例 #2
0
def getField(entry, info):
    tmp = entry

    # Skip based on exclude data
    for f in info.get("exclude", "").split("."):
        tmp = tmp.get(f)
        if tmp is None:
            break
    if tmp:
        return None

    tmp = entry

    for f in info.get("field", "").split("."):
        tmp = tmp.get(f)
        if tmp is None:
            heslog.error("entry error on %s" % entry)
            return None
    return tmp
コード例 #3
0
ファイル: postDeploy.py プロジェクト: ndlib/dave
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 {}
コード例 #4
0
    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
コード例 #5
0
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 {}
コード例 #6
0
    def createEntry(self, item, shouldPublish=False):
        contentType = item.get("sys", {}).get("contentType",
                                              {}).get("sys", {}).get("id")
        if contentType is None:
            heslog.error("item has no specified contentType %s" % item)
            return None

        heslog.addContext(contentType=contentType)

        headers = {'x-contentful-content-type': contentType}

        data = {"fields": item.get("fields", {})}

        # we're have to know what the unique field(s) are for each content type to do this search correctly
        constraints = {
            "fields.url": item.get("fields", {}).get("url", {}).get(LOC_US)
        }
        constraints["content_type"] = contentType
        currentEntry = self.getCurrentObject(TYPE_ENTRY, constraints)

        return self._createOrUpdate(TYPE_ENTRY, data, headers, None,
                                    currentEntry, shouldPublish)
コード例 #7
0
    def _checkSys(self, responseObj, defaultVal=None):
        sys = responseObj.get("sys", {})
        sysType = sys.get("type", None)

        if sysType is None:
            heslog.error("No sys was found in response %s" % responseObj)
            return defaultVal

        if sysType == "Error":
            heslog.error(sys.get("id", ""))
            details = responseObj.get("details")
            if details is not None:
                heslog.error(details)
            return defaultVal

        return sys
コード例 #8
0
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))
コード例 #9
0
ファイル: logTest.py プロジェクト: ndlib/hesburgh_utilities
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")