Projet

Général

Profil

0001-import_site-remove-obsolete-dry-run-provisionning-pr.patch

Valentin Deniaud, 25 mai 2021 15:46

Télécharger (2,14 ko)

Voir les différences:

Subject: [PATCH] import_site: remove obsolete dry run provisionning protection
 (#51462)

 .../management/commands/import_site.py        | 24 ++++---------------
 1 file changed, 5 insertions(+), 19 deletions(-)
src/authentic2/management/commands/import_site.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import contextlib
18 17
import json
19 18
import sys
20 19

  
......
42 41
    return kwargs
43 42

  
44 43

  
45
#  Borrowed from https://bugs.python.org/issue10049#msg118599
46
@contextlib.contextmanager
47
def provision_contextm(dry_run, settings):
48
    if dry_run and 'hobo.agent.authentic2' in settings.INSTALLED_APPS:
49
        import hobo.agent.authentic2
50

  
51
        with hobo.agent.authentic2.provisionning.Provisionning():
52
            yield
53
    else:
54
        yield
55

  
56

  
57 44
class Command(BaseCommand):
58 45
    help = 'Import site'
59 46

  
......
83 70
        c_kwargs = create_context_args(options)
84 71
        try:
85 72
            with open(filename, 'r') as f:
86
                with provision_contextm(dry_run, settings):
87
                    with transaction.atomic():
88
                        sys.stdout.write(msg)
89
                        result = import_site(json.load(f), ImportContext(**c_kwargs))
90
                        if dry_run:
91
                            raise DryRunException()
73
                with transaction.atomic():
74
                    sys.stdout.write(msg)
75
                    result = import_site(json.load(f), ImportContext(**c_kwargs))
76
                    if dry_run:
77
                        raise DryRunException()
92 78
        except DryRunException:
93 79
            pass
94 80
        sys.stdout.write(result.to_str())
95
-