Skip to content

Commit

Permalink
feat: mv function, stub for module patching
Browse files Browse the repository at this point in the history
  • Loading branch information
amarao committed Feb 29, 2024
1 parent dfa4ca1 commit 56dc008
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/strategy/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from contextlib import ContextDecorator
import os
import difflib


# Written by @AKrumov
Expand Down Expand Up @@ -61,13 +62,18 @@ def loaders_path():

def core_path():
from mitogen import core

return core.__file__


class patches(ContextDecorator):
ORIG_LINE = "ANSIBLE_VERSION_MAX = (2, 13)\n"
PATCH_LINE = "ANSIBLE_VERSION_MAX = (2, 16)\n"

def mv(self, src, dst):
os.move(src, dst)
self.renames.append({"module": src, "original": dst})

def __enter__(self):
# did this process patched it or it's concurrent process?
self.patched = False
Expand Down Expand Up @@ -103,6 +109,7 @@ def __enter__(self):
# lock for patching.

self.patched = True

# version patch
self.renames.append(
{
Expand All @@ -118,6 +125,11 @@ def __enter__(self):
dest.write(line)
return self

# bug 1034 patch
core_module = core_path()
core_module_orig = core_module + ".orig"
self.mv(core_module, core_module_orig)

def __exit__(self, *exc):
if self.patched:
for rename in self.renames:
Expand Down

0 comments on commit 56dc008

Please sign in to comment.