Add workshift variables to all dictionaries passed to templates.
329368
def add_workshift_context(request):
    
    if not request.user.is_authenticated():
        return {}

    if Semester.objects.count() < 1:
        return {
            "WORKSHIFT_ENABLED": False,
        }

    # Current semester is for navbar notifications
    try:
        current_semester = Semester.objects.get(current=True)
    except Semester.DoesNotExist:
        current_semester = None
    except Semester.MultipleObjectsReturned:
        current_semester = Semester.objects.filter(
            current=True,
        ).latest("start_date")
        workshift_emails = []
        for pos in Manager.objects.filter(workshift_manager=True, active=True):
            if pos.email:
                workshift_emails.append(pos.email)
            elif pos.incumbent.email_visible and pos.incumbent.user.email:
                workshift_emails.append(pos.incumbent.user.email)
        if workshift_emails:
            workshift_email_str = " ({})".format(
                ", ".join(
                    "<a href=\"mailto:{0}\">{0}</a>".format(i)
                    for i in workshift_emails
                ),
            )
        else:
            workshift_email_str = ""
        messages.add_message(
            request,
            messages.WARNING,
            MESSAGES["MULTIPLE_CURRENT_SEMESTERS"].format(
                admin_email=settings.ADMINS[0][1],
                workshift_emails=workshift_email_str,
            ),
        )

    today = localtime(now()).date()

    days_passed = None
    total_days = None
    semester_percentage = None
    standing = None
    happening_now = None
    workshift_profile = None

    if current_semester:
        # number of days passed in this semester
        days_passed = (today - current_semester.start_date).days

        # total number of days in this semester
        total_days = (
            current_semester.end_date - current_semester.start_date
        ).days
        semester_percentage = round((days_passed / total_days) * 100, 2)

    # Semester is for populating the current page
    try:
        semester = request.semester
    except AttributeError:
        semester = current_semester

    try:
        workshift_profile = WorkshiftProfile.objects.get(
            semester=semester,
            user=request.user,
            )
    except WorkshiftProfile.DoesNotExist:
        workshift_profile = None

    workshift_manager = utils.can_manage(request.user, semester=semester)

    upcoming_shifts = WorkshiftInstance.objects.filter(
        workshifter=workshift_profile,
        closed=False,
        date__gte=today,
        date__lte=today + timedelta(days=2),
    )

    # TODO: Add a fudge factor of an hour to this?
    time = localtime(now()).time()
    happening_now = []
    for shift in upcoming_shifts:
        if shift.week_long:
            happening_now.append(shift)
            continue
        if shift.date != today:
            continue
        if shift.start_time is None:
            if shift.end_time is not None:
                if time < shift.end_time:
                    happening_now.append(shift)
            else:
                happening_now.append(shift)
            continue
        if shift.end_time is None:
            if shift.start_time is not None:
                if time > shift.start_time:
                    happening_now.append(shift)
            else:
                happening_now.append(shift)
            continue
        if time > shift.start_time and time < shift.end_time:
            happening_now.append(shift)

    if workshift_profile:
        try:
            standing = workshift_profile.pool_hours.get(
                pool__is_primary=True,
            ).standing
        except (PoolHours.DoesNotExist, PoolHours.MultipleObjectsReturned):
            pass

    return {
        "WORKSHIFT_ENABLED": True,
        "SEMESTER": semester,
        "CURRENT_SEMESTER": current_semester,
        "WORKSHIFT_MANAGER": workshift_manager,
        "WORKSHIFT_PROFILE": workshift_profile,
        "STANDING": standing,
        "DAYS_PASSED": days_passed,
        "TOTAL_DAYS": total_days,
        "SEMESTER_PERCENTAGE": semester_percentage,
        "UPCOMING_SHIFTS": zip(upcoming_shifts, happening_now),
    }
1271295
def _workaround_no_stage_specific_variables(project):
    """"""
    for (name, var) in project.stage.variables.items():
        yield "variable %s" % name
    for (name, _list) in project.stage.lists.items():
        yield "list %s" % name
    project.variables.update(project.stage.variables)
    project.lists.update(project.stage.lists)
    project.stage.variables = {}
    project.stage.lists = {}
771004
function addShift_(x, y, ys) {
  var i, c, k, kk;
  k=x.length<ys+y.length ? x.length : ys+y.length;
  kk=x.length;
  for (c=0, i=ys; i<k; i++) {
    c+=x[i]+y[i-ys];
    x[i]=c & mask;
    c>>=bpe;
  }
  for (i=k; c && i<kk; i++) {
    c+=x[i];
    x[i]=c & mask;
    c>>=bpe;
  }
}
1005931
def setup_dictionary(self, task):
        """"""

        dictionary_options = task.get('dictionary', {})
        output = os.path.abspath(dictionary_options.get('output', self.dict_bin))
        lang = dictionary_options.get('lang', 'en_US')
        wordlists = dictionary_options.get('wordlists', [])
        if lang and wordlists:
            self.compile_dictionary(lang, dictionary_options.get('wordlists', []), None, output)
        else:
            output = None
        return output
973026
function addTemplateToCompiler (mainCompiler, templatePath) {
  const childCompiler = getChildCompiler(mainCompiler);
  const isNew = childCompiler.addTemplate(templatePath);
  if (isNew) {
    clearCache(mainCompiler);
  }
}
909182
def _adjust_template(filepath, translate):
    
    with open(filepath, 'r') as file:
        filedata = file.read()

    filedata = _multiple_replace(filedata, translate)

    with open(filepath, 'w') as file:
        file.write(filedata)
751999
def update(self, other_dict):
        """"""
        for key, value in iter_multi_items(other_dict):
            MultiDict.add(self, key, value)
174809
def add_unique_template_variables(self, options):
        """"""
        options.update(dict(
            colorStops=self.color_stops,
            colorDefault=self.color_default,
            radiusStops=self.radius_stops,
            clusterRadius=self.clusterRadius,
            clusterMaxZoom=self.clusterMaxZoom,
            strokeWidth=self.stroke_width,
            strokeColor=self.stroke_color,
            radiusDefault=self.radius_default,
            highlightColor=self.highlight_color
        ))
716376
def add_defaults_to_kwargs(defaults, **kwargs):
    
    defaults = dict(defaults)
    defaults.update(kwargs)
    return defaults
1085311
def _merge_unbound_var_dicts(src, dst):
  """"""
  for k, v in six.iteritems(src):
    if dst.get(k, v) != v:
      trace1 = ''.join(scopes.skip_common_stack_elements(v.stacktrace, dst[
          k].stacktrace))
      trace2 = ''.join(
          scopes.skip_common_stack_elements(dst[k].stacktrace, v.stacktrace))
      raise ValueError('Key conflict: %s\nDefined At:\n%s\nand\n%s' %
                       (k, trace1, trace2))
    else:
      dst[k] = v
55714
def build_vars(path=None):
        """"""
        init_vars = {
            "__name__": "__main__",
            "__package__": None,
            "reload": reload,
        }
        if path is not None:
            init_vars["__file__"] = fixpath(path)
        # put reserved_vars in for auto-completion purposes
        for var in reserved_vars:
            init_vars[var] = None
        return init_vars
647748
def add_to(self, parent, additions):
        ""
        for x in additions:
            if x not in parent:
                parent.append(x)
                self.changed()
1149179
def expand_variables(template_str, value_map, transformer=None):
  
  if template_str is None:
    return None
  else:
    if transformer is None:
      transformer = lambda v: v
    try:
      # Don't bother iterating items for Python 2+3 compatibility.
      transformed_value_map = {k: transformer(value_map[k]) for k in value_map}
      return Template(template_str).substitute(transformed_value_map)
    except Exception as e:
      raise ValueError("could not expand variable names in command '%s': %s" % (template_str, e))
153658
def load_default_templates(self):
        """"""
        for importer, modname, is_pkg in pkgutil.iter_modules(templates.__path__):
            self.register_template('.'.join((templates.__name__, modname)))
369088
def _add_attrs(self):
        ''''''
        for attr in self.template_attrs:
            attr_value = self._get_template_attr(attr)

            if not attr_value:
                continue

            attr, attr_value = self._transform_key_value(
                attr,
                attr_value,
                self.attr_map
            )
            self.templ_dict[attr] = attr_value
398120
def build_stack_changes(stack_name, new_stack, old_stack, new_params,
                        old_params):
    """"""
    from_file = "old_%s" % (stack_name,)
    to_file = "new_%s" % (stack_name,)
    lines = difflib.context_diff(
        old_stack, new_stack,
        fromfile=from_file, tofile=to_file,
        n=7)  # ensure at least a few lines of context are displayed afterward

    template_changes = list(lines)
    log_lines = []
    if not template_changes:
        log_lines.append("*** No changes to template ***")
    param_diffs = diff_parameters(old_params, new_params)
    if param_diffs:
        log_lines.append(format_params_diff(param_diffs))
    if template_changes:
        log_lines.append("".join(template_changes))
    return log_lines
206426
def add_variables(vars)
      # Store all the variables in the model
      # Most of the work will be done when we add the constraints
      vars.each do |var|
        var.model = self
        var.index = @variables.count
        @variables << var
      end
    end