Finds the last good release and run for a build.
336890
def _find_last_good_run(build):
    """"""
    run_name = request.form.get('run_name', type=str)
    utils.jsonify_assert(run_name, 'run_name required')

    last_good_release = (
        models.Release.query
        .filter_by(
            build_id=build.id,
            status=models.Release.GOOD)
        .order_by(models.Release.created.desc())
        .first())

    last_good_run = None

    if last_good_release:
        logging.debug('Found last good release for: build_id=%r, '
                      'release_name=%r, release_number=%d',
                      build.id, last_good_release.name,
                      last_good_release.number)
        last_good_run = (
            models.Run.query
            .filter_by(release_id=last_good_release.id, name=run_name)
            .first())
        if last_good_run:
            logging.debug('Found last good run for: build_id=%r, '
                          'release_name=%r, release_number=%d, '
                          'run_name=%r',
                          build.id, last_good_release.name,
                          last_good_release.number, last_good_run.name)

    return last_good_release, last_good_run
1290270
def run():
    """"""
    args = parse()
    build_results = [build(p) for p in glob.iglob(glob_path)]

    if not args['publish']:
        return

    for entry in build_results:
        publish(entry)
575543
def runtime_to_build(runtime_deps):
    """"""
    build_deps = copy.deepcopy(runtime_deps)
    for dep in build_deps:
        if len(dep) > 0:
            dep[0] = 'BuildRequires'
    return build_deps
402946
def status(self, key, value):
        """"""
        value = value.lower()
        if value not in valid_statuses:
            raise ValueError("Build Status must have a value from:\n{}".format(", ".join(valid_statuses)))

        self.obj['status'][key] = value
        self.changes.append("Updating build:{}.status.{}={}"
                            .format(self.obj['name'], key, value))
        return self
396767
def run(self):
    """"""

    module = self.distribution.ext_modules[0]
    base_dir = os.path.dirname(__file__)

    if base_dir:
      os.chdir(base_dir)

    exclusions = []

    for define in self.define or []:
      module.define_macros.append(define)

    for library in self.libraries or []:
      module.libraries.append(library)

    building_for_windows = self.plat_name in ('win32','win-amd64')
    building_for_osx = 'macosx' in self.plat_name
    building_for_linux = 'linux' in self.plat_name
    building_for_freebsd = 'freebsd' in self.plat_name
    building_for_openbsd = 'openbsd' in self.plat_name # need testing

    if building_for_linux:
      module.define_macros.append(('USE_LINUX_PROC', '1'))
    elif building_for_windows:
      module.define_macros.append(('USE_WINDOWS_PROC', '1'))
      module.define_macros.append(('_CRT_SECURE_NO_WARNINGS', '1'))
      module.libraries.append('kernel32')
      module.libraries.append('advapi32')
      module.libraries.append('user32')
      module.libraries.append('crypt32')
      module.libraries.append('ws2_32')
    elif building_for_osx:
      module.define_macros.append(('USE_MACH_PROC', '1'))
      module.include_dirs.append('/usr/local/opt/openssl/include')
      module.include_dirs.append('/opt/local/include')
      module.library_dirs.append('/opt/local/lib')
      module.include_dirs.append('/usr/local/include')
      module.library_dirs.append('/usr/local/lib')
    elif building_for_freebsd:
      module.define_macros.append(('USE_FREEBSD_PROC', '1'))
      module.include_dirs.append('/opt/local/include')
      module.library_dirs.append('/opt/local/lib')
      module.include_dirs.append('/usr/local/include')
      module.library_dirs.append('/usr/local/lib')
    elif building_for_openbsd:
      module.define_macros.append(('USE_OPENBSD_PROC', '1'))
      module.include_dirs.append('/opt/local/include')
      module.library_dirs.append('/opt/local/lib')
      module.include_dirs.append('/usr/local/include')
      module.library_dirs.append('/usr/local/lib')
    else:
      module.define_macros.append(('USE_NO_PROC', '1'))

    if has_function('memmem'):
      module.define_macros.append(('HAVE_MEMMEM', '1'))
    if has_function('strlcpy'):
      module.define_macros.append(('HAVE_STRLCPY', '1'))
    if has_function('strlcat'):
      module.define_macros.append(('HAVE_STRLCAT', '1'))

    if self.enable_profiling:
      module.define_macros.append(('PROFILING_ENABLED', '1'))

    if self.dynamic_linking:
      module.libraries.append('yara')
    else:
      if not self.define or not ('HASH_MODULE', '1') in self.define:
        if (has_function('MD5_Init', libraries=['crypto']) and
            has_function('SHA256_Init', libraries=['crypto'])):
          module.define_macros.append(('HASH_MODULE', '1'))
          module.define_macros.append(('HAVE_LIBCRYPTO', '1'))
          module.libraries.append('crypto')
        else:
          exclusions.append('yara/libyara/modules/hash.c')

      if self.enable_magic:
        module.define_macros.append(('MAGIC_MODULE', '1'))
        module.libraries.append('magic')
      else:
        exclusions.append('yara/libyara/modules/magic.c')

      if self.enable_cuckoo:
        module.define_macros.append(('CUCKOO_MODULE', '1'))
        module.libraries.append('jansson')
      else:
        exclusions.append('yara/libyara/modules/cuckoo.c')

      if self.enable_dotnet:
        module.define_macros.append(('DOTNET_MODULE', '1'))
      else:
        exclusions.append('yara/libyara/modules/dotnet.c')

      if self.enable_dex:
        module.define_macros.append(('DEX_MODULE', '1'))
      else:
        exclusions.append('yara/libyara/modules/dex.c')

      if self.enable_macho:
        module.define_macros.append(('MACHO_MODULE', '1'))
      else:
        exclusions.append('yara/libyara/modules/macho.c')

      exclusions = [os.path.normpath(x) for x in exclusions]

      for directory, _, files in os.walk('yara/libyara/'):
        for x in files:
          x = os.path.normpath(os.path.join(directory, x))
          if x.endswith('.c') and x not in exclusions:
            module.sources.append(x)

    build_ext.run(self)
1334594
function (seq, release, done) {
      lockRelease = release
      latestSeq = seq

      hashNodesAndFindLinks(nodes, done)
    }
746847
function finishRelease() {

  log.done();
  execSync("npm run examples", {stdio: "inherit"});
  execSync("npm run docs", {stdio: "inherit"});
  let commits = "", releaseUrl = "", zipSize = 0;

  log.timer("compiling release notes");
  execAsync("git log --pretty=format:'* %s (%h)' `git describe --tags --abbrev=0`...HEAD")
    .then(stdout => {
      commits = stdout;
      log.timer("publishing npm package");
      return execAsync("npm publish ./");
    })
    .then(() => {
      log.timer("commiting all modified files for release");
      return execAsync("git add --all");
    })
    .then(() => execAsync(`git commit -m \"compiles v${version}\"`))
    .then(() => {
      log.timer("tagging latest commit");
      return execAsync(`git tag v${version}`);
    })
    .then(() => {
      log.timer("pushing to repository");
      return execAsync("git push origin --follow-tags");
    })
    .then(() => {
      log.timer("publishing release notes");
      github.authenticate({type: "oauth", token});
      return github.repos.createRelease({
        owner: "d3plus",
        repo: name,
        tag_name: `v${version}`,
        name: `v${version}`,
        body: commits,
        prerelease
      });
    })
    .then(() => {
      log.timer("attaching .zip distribution to release");
      return github.repos.getReleaseByTag({
        owner: "d3plus",
        repo: name,
        tag: `v${version}`
      });
    })
    .then(release => {
      releaseUrl = release.data.upload_url;
      zipSize = fs.statSync(`build/${name}.zip`).size;

      return github.repos.uploadAsset({
        url: releaseUrl,
        file: fs.createReadStream(`build/${name}.zip`),
        contentType: "application/zip",
        contentLength: zipSize,
        name: `${name}.zip`,
        label: `${name}.zip`,
        owner: "d3plus",
        repo: name
      });

    })
    .then(() => {
      log.exit();
      shell.exit(0);
    })
    .catch(err => {
      log.fail(err);
      log.exit();
      shell.exit(1);
    });

}
203436
def call(release, _options = {})
      Dir.chdir(release.build_path.to_s) do
        @pattern.each do |pattern|
          Dir.glob(pattern).each do |file|
            clean_path(release, file)
          end
        end
      end
    end
827149
def finish(build_script_lines)
      # keep track of changed files
      start_id = @git.latest_id("tetra: dry-run-started")
      changed_files = @git.changed_files("src", start_id)

      # revert to pre-dry-run status
      @git.revert_directories(["src"], start_id)

      # prepare commit comments
      comments = ["Dry run finished\n", "tetra: dry-run-finished"]
      comments += changed_files.map { |f| "tetra: file-changed: #{f}" }
      comments += build_script_lines.map { |l| "tetra: build-script-line: #{l}" }

      # commit end of dry run
      @git.commit_directories(["kit"], comments.join("\n"))
    end
31375
def report_run():
    """"""
    build = g.build
    release, run = _get_or_create_run(build)

    db.session.refresh(run, lockmode='update')

    current_url = request.form.get('url', type=str)
    current_image = request.form.get('image', type=str)
    current_log = request.form.get('log', type=str)
    current_config = request.form.get('config', type=str)

    ref_url = request.form.get('ref_url', type=str)
    ref_image = request.form.get('ref_image', type=str)
    ref_log = request.form.get('ref_log', type=str)
    ref_config = request.form.get('ref_config', type=str)

    diff_failed = request.form.get('diff_failed', type=str)
    diff_image = request.form.get('diff_image', type=str)
    diff_log = request.form.get('diff_log', type=str)

    distortion = request.form.get('distortion', default=None, type=float)
    run_failed = request.form.get('run_failed', type=str)

    if current_url:
        run.url = current_url
    if current_image:
        run.image = current_image
    if current_log:
        run.log = current_log
    if current_config:
        run.config = current_config
    if current_image or current_log or current_config:
        logging.info('Saving run data: build_id=%r, release_name=%r, '
                     'release_number=%d, run_name=%r, url=%r, '
                     'image=%r, log=%r, config=%r, run_failed=%r',
                     build.id, release.name, release.number, run.name,
                     run.url, run.image, run.log, run.config, run_failed)

    if ref_url:
        run.ref_url = ref_url
    if ref_image:
        run.ref_image = ref_image
    if ref_log:
        run.ref_log = ref_log
    if ref_config:
        run.ref_config = ref_config
    if ref_image or ref_log or ref_config:
        logging.info('Saved reference data: build_id=%r, release_name=%r, '
                     'release_number=%d, run_name=%r, ref_url=%r, '
                     'ref_image=%r, ref_log=%r, ref_config=%r',
                     build.id, release.name, release.number, run.name,
                     run.ref_url, run.ref_image, run.ref_log, run.ref_config)

    if diff_image:
        run.diff_image = diff_image
    if diff_log:
        run.diff_log = diff_log
    if distortion:
        run.distortion = distortion

    if diff_image or diff_log:
        logging.info('Saved pdiff: build_id=%r, release_name=%r, '
                     'release_number=%d, run_name=%r, diff_image=%r, '
                     'diff_log=%r, diff_failed=%r, distortion=%r',
                     build.id, release.name, release.number, run.name,
                     run.diff_image, run.diff_log, diff_failed, distortion)

    if run.image and run.diff_image:
        run.status = models.Run.DIFF_FOUND
    elif run.image and run.ref_image and not run.diff_log:
        run.status = models.Run.NEEDS_DIFF
    elif run.image and run.ref_image and not diff_failed:
        run.status = models.Run.DIFF_NOT_FOUND
    elif run.image and not run.ref_config:
        run.status = models.Run.NO_DIFF_NEEDED
    elif run_failed or diff_failed:
        run.status = models.Run.FAILED
    else:
        # NOTE: Intentionally do not transition state here in the default case.
        # We allow multiple background workers to be writing to the same Run in
        # parallel updating its various properties.
        pass

    # TODO: Verify the build has access to both the current_image and
    # the reference_sha1sum so they can't make a diff from a black image
    # and still see private data in the diff image.

    if run.status == models.Run.NEEDS_DIFF:
        task_id = '%s:%s:%s' % (run.id, run.image, run.ref_image)
        logging.info('Enqueuing pdiff task=%r', task_id)

        work_queue.add(
            constants.PDIFF_QUEUE_NAME,
            payload=dict(
                build_id=build.id,
                release_name=release.name,
                release_number=release.number,
                run_name=run.name,
                run_sha1sum=run.image,
                reference_sha1sum=run.ref_image,
            ),
            build_id=build.id,
            release_id=release.id,
            run_id=run.id,
            source='report_run',
            task_id=task_id)

    # Flush the run so querying for Runs in _check_release_done_processing
    # will be find the new run too and we won't deadlock.
    db.session.add(run)
    db.session.flush()

    _check_release_done_processing(release)
    db.session.commit()

    signals.run_updated_via_api.send(
        app, build=build, release=release, run=run)

    logging.info('Updated run: build_id=%r, release_name=%r, '
                 'release_number=%d, run_name=%r, status=%r',
                 build.id, release.name, release.number, run.name, run.status)

    return flask.jsonify(success=True)
484591
def run():
    """"""
    logfilename = os.path.join(current_app.config['CFG_LOGDIR'],
                               'invenio_upgrader.log')
    upgrader = InvenioUpgrader()
    logger = upgrader.get_logger(logfilename=logfilename)

    try:
        upgrades = upgrader.get_upgrades()

        if not upgrades:
            logger.info("All upgrades have been applied.")
            return

        logger.info("Following upgrade(s) will be applied:")

        for u in upgrades:
            logger.info(" * %s (%s)" % (u.name, u.info))

        logger.info("Running pre-upgrade checks...")
        upgrader.pre_upgrade_checks(upgrades)

        logger.info("Calculating estimated upgrade time...")
        estimate = upgrader.human_estimate(upgrades)

        click.confirm(
            "You are going to upgrade your installation "
            "(estimated time: {0})!".format(estimate), abort=True)

        for u in upgrades:
            logger.info("Applying %s (%s)" % (u.name, u.info))
            upgrader.apply_upgrade(u)

        logger.info("Running post-upgrade checks...")
        upgrader.post_upgrade_checks(upgrades)

        if upgrader.has_warnings():
            logger.warning("Upgrade completed with %s warnings - please check "
                           "log-file for further information:\nless %s"
                           % (upgrader.get_warnings_count(), logfilename))
        else:
            logger.info("Upgrade completed successfully.")
    except RuntimeError as e:
        for msg in e.args:
            logger.error(unicode(msg))
        logger.info("Please check log file for further information:\n"
                    "less %s" % logfilename)
        click.Abort()
417440
def _get_or_create_run(build):
    """"""
    release_name, release_number = _get_release_params()
    run_name = request.form.get('run_name', type=str)
    utils.jsonify_assert(run_name, 'run_name required')

    release = (
        models.Release.query
        .filter_by(build_id=build.id, name=release_name, number=release_number)
        .first())
    utils.jsonify_assert(release, 'release does not exist')

    run = (
        models.Run.query
        .filter_by(release_id=release.id, name=run_name)
        .first())
    if not run:
        # Ignore re-reports of the same run name for this release.
        logging.info('Created run: build_id=%r, release_name=%r, '
                     'release_number=%d, run_name=%r',
                     build.id, release.name, release.number, run_name)
        run = models.Run(
            release_id=release.id,
            name=run_name,
            status=models.Run.DATA_PENDING)
        db.session.add(run)
        db.session.flush()

    return release, run
880180
function checkThatExecutableExists(next) {
        fs.exists(nodeCompiler.releasePath, function(exists) {
          if (!exists) {
            _log(
              'error',
              'The release executable has not been generated. ' +
                'This indicates a failure in the build process. ' +
                'There is likely additional information above.',
            );
            process.exit(1);
          } else {
            next();
          }
        });
      }
1115275
def buildFinished(self, build, wfb):
        """"""

        # by the time we get here, the Build has already released the worker,
        # which will trigger a check for any now-possible build requests
        # (maybeStartBuilds)

        results = build.build_status.getResults()

        self.building.remove(build)
        if results == RETRY:
            d = self._resubmit_buildreqs(build)
            d.addErrback(log.err, 'while resubmitting a build request')
        else:
            complete_at_epoch = self.master.reactor.seconds()
            complete_at = epoch2datetime(complete_at_epoch)
            brids = [br.id for br in build.requests]

            d = self.master.data.updates.completeBuildRequests(
                brids, results, complete_at=complete_at)
            # nothing in particular to do with this deferred, so just log it if
            # it fails..
            d.addErrback(log.err, 'while marking build requests as completed')

        if wfb.worker:
            wfb.worker.releaseLocks()
126863
public static function lastBuilt()
    {
        $file = TEMP_PATH
            . DIRECTORY_SEPARATOR
            . 'database-last-generated-'
            . str_replace(array('\\','/',':'), '.', Director::baseFolder());

        if (file_exists($file)) {
            return filemtime($file);
        }
        return null;
    }
324799
def run_build(which_build='default', options={})
      formatter = options[:formatter] || Fudge::Formatters::Simple.new
      output_start(which_build, formatter)
      status = run(which_build, options)
      output_status(status, formatter)
    end
219817
def get_releases(data, **kwargs):
    
    if "versions" in data:
        return sorted(data["versions"].keys(), key=lambda v: parse(v), reverse=True)
    return []