import_site: remove obsolete dry run provisionning protection (#51462)

This commit is contained in:
Valentin Deniaud 2021-05-25 15:00:53 +02:00
parent 92a9886872
commit 24d42824dd
1 changed files with 5 additions and 19 deletions

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import contextlib
import json import json
import sys import sys
@ -42,18 +41,6 @@ def create_context_args(options):
return kwargs return kwargs
# Borrowed from https://bugs.python.org/issue10049#msg118599
@contextlib.contextmanager
def provision_contextm(dry_run, settings):
if dry_run and 'hobo.agent.authentic2' in settings.INSTALLED_APPS:
import hobo.agent.authentic2
with hobo.agent.authentic2.provisionning.Provisionning():
yield
else:
yield
class Command(BaseCommand): class Command(BaseCommand):
help = 'Import site' help = 'Import site'
@ -83,12 +70,11 @@ class Command(BaseCommand):
c_kwargs = create_context_args(options) c_kwargs = create_context_args(options)
try: try:
with open(filename, 'r') as f: with open(filename, 'r') as f:
with provision_contextm(dry_run, settings): with transaction.atomic():
with transaction.atomic(): sys.stdout.write(msg)
sys.stdout.write(msg) result = import_site(json.load(f), ImportContext(**c_kwargs))
result = import_site(json.load(f), ImportContext(**c_kwargs)) if dry_run:
if dry_run: raise DryRunException()
raise DryRunException()
except DryRunException: except DryRunException:
pass pass
sys.stdout.write(result.to_str()) sys.stdout.write(result.to_str())