Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
latest_version = Process.objects.filter(slug=slug).aggregate(
Max("version")
)["version__max"]
if latest_version is not None and latest_version > int_version:
self.stderr.write(
"Skip processor {}: newer version installed".format(slug)
)
continue
previous_process_qs = Process.objects.filter(slug=slug)
if previous_process_qs.exists():
previous_process = previous_process_qs.latest()
else:
previous_process = None
process_query = Process.objects.filter(slug=slug, version=version)
if process_query.exists():
if not force:
if verbosity > 0:
self.stdout.write(
"Skip processor {}: same version installed".format(slug)
)
continue
process_query.update(**p)
log_processors.append("Updated {}".format(slug))
else:
process = Process.objects.create(contributor=user, **p)
assign_contributor_permissions(process)
if previous_process:
copy_permissions(previous_process, process)
log_processors.append("Inserted {}".format(slug))
def handle(self, *args, **options):
"""Handle command list_docker_images."""
verbosity = int(options.get("verbosity"))
# Check that the specified output format is valid
if options["format"] != "plain" and options["format"] != "yaml":
raise CommandError("Unknown output format: %s" % options["format"])
# Gather only unique latest custom Docker requirements that the processes are using
# The 'image' field is optional, so be careful about that as well
unique_docker_images = set(
p.requirements["executor"]["docker"]["image"]
for p in Process.objects.filter(is_active=True)
.order_by("slug", "-version")
.distinct("slug")
.only("requirements")
.filter(requirements__icontains="docker")
if "image" in p.requirements.get("executor", {}).get("docker", {})
)
# Add the default image.
unique_docker_images.add(DEFAULT_CONTAINER_IMAGE)
# Pull images if requested or just output the list in specified format
if options["pull"]:
# Remove set of already pulled images.
with PULLED_IMAGES_LOCK:
unique_docker_images.difference_update(PULLED_IMAGES)
}
for index, step in enumerate(steps):
try:
step_id = step["id"]
step_slug = step["run"]
except KeyError as error:
raise ExecutionError(
'Incorrect definition of step "{}", missing property "{}".'.format(
step.get("id", index), error
)
)
# Fetch target process.
process = (
Process.objects.filter(slug=step_slug).order_by("-version").first()
)
if not process:
raise ExecutionError(
'Incorrect definition of step "{}", invalid process "{}".'.format(
step_id, step_slug
)
)
# Process all input variables.
step_input = step.get("input", {})
if not isinstance(step_input, dict):
raise ExecutionError(
'Incorrect definition of step "{}", input must be a dictionary.'.format(
step_id
)
)
- If they have data: flag them not active (``is_active=False``)
"""
process_slugs = set(ps["slug"] for ps in process_schemas)
# Processes that are in DB but not in the code
retired_processes = Process.objects.filter(~Q(slug__in=process_slugs))
# Remove retired processes which do not have data
retired_processes.filter(data__exact=None).delete()
# Remove non-latest processes which do not have data
latest_version_processes = Process.objects.order_by(
"slug", "-version"
).distinct("slug")
Process.objects.filter(data__exact=None).difference(
latest_version_processes
).delete()
# Deactivate retired processes which have data
retired_processes.update(is_active=False)