We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[beta][v16][rc1] Les contenus extra (pdf, epub, etc.) ne sont pas générés lors de la 2nde validation
Version 16 RC1.

Scénario de test : 
- Je publie un tutoriel pris en zone de validation (J'ai pris celui sur les bases de la prog)
- Le tutoriel est réservé, publié.
- Je modifie le sous-titre du tutoriel et redemande sa validation (2 min après la première publication)
- Je le réserver puis publie une fois de plus le tutoriel sans cocher la case maj majeur, donc en version mineure
- Le tutoriel est publié cette fois, mais après 5 min, toujours pas de signe d'un pdf ni epub, etc.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zds/tutorialv2/management/commands/publication_watchdog.py`
Content:
```
1 # coding: utf-8
2 from os.path import dirname, join
3 import os
4 import time
5 
6 import shutil
7 from django.core.management import BaseCommand
8 from pathtools.path import listdir
9 from watchdog.observers import Observer
10 from watchdog.events import FileCreatedEvent, FileSystemEventHandler, LoggingEventHandler
11 from zds import settings
12 from zds.tutorialv2.publication_utils import generate_exernal_content
13 from codecs import open
14 
15 
16 class TutorialIsPublished(FileSystemEventHandler):
17     prepare_callbacks = []  # because we can imagine we will create far more than test directory existence
18     finish_callbacks = []  # because we can imagine we will send a PM on success or failure one day
19 
20     @staticmethod
21     def __create_dir(extra_contents_path):
22         if not os.path.exists(extra_contents_path):
23                 os.makedirs(extra_contents_path)
24 
25     @staticmethod
26     def __cleanup_build_and_watchdog(extra_contents_path, watchdog_file_path):
27         for listed in listdir(extra_contents_path, recursive=False):
28             try:
29                 shutil.copy(join(extra_contents_path, listed), extra_contents_path.replace("__building", ""))
30             except Exception:
31                 pass
32         shutil.rmtree(extra_contents_path)
33         os.remove()
34 
35     def __init__(self):
36         self.prepare_callbacks = [TutorialIsPublished.__create_dir]
37         self.finish_callbacks = [TutorialIsPublished.__cleanup_build_and_watchdog]
38 
39     def on_created(self, event):
40         super(TutorialIsPublished, self).on_created(event)
41         pandoc_debug_str = ""
42 
43         if settings.PANDOC_LOG_STATE:
44             pandoc_debug_str = " 2>&1 | tee -a " + settings.PANDOC_LOG
45         if isinstance(event, FileCreatedEvent):
46             with open(event.src_path, encoding="utf-8") as f:
47                 infos = f.read().strip().split(";")
48             md_file_path = infos[1]
49             base_name = infos[0]
50             extra_contents_path = dirname(md_file_path)
51             self.prepare_generation(extra_contents_path)
52             try:
53                 generate_exernal_content(base_name, extra_contents_path, md_file_path,
54                                          pandoc_debug_str, overload_settings=True)
55             finally:
56                 self.finish_generation(extra_contents_path, event.src_path)
57 
58     def prepare_generation(self, extra_contents_path):
59 
60         for callback in self.prepare_callbacks:
61             callback(extra_contents_path)
62 
63     def finish_generation(self, extra_contents_path, watchdog_file_path):
64         for callback in self.finish_callbacks:
65             callback(extra_contents_path, watchdog_file_path)
66 
67 
68 class Command(BaseCommand):
69     help = 'Launch a watchdog that generate all exported formats (epub, pdf...) files without blocking request handling'
70 
71     def handle(self, *args, **options):
72         path = settings.ZDS_APP['content']['extra_content_watchdog_dir']
73         event_handler = TutorialIsPublished()
74         observer = Observer()
75         observer.schedule(event_handler, path, recursive=True)
76         observer.schedule(LoggingEventHandler(), path)
77         observer.start()
78         try:
79             while True:
80                 time.sleep(1)
81         except KeyboardInterrupt:
82             observer.stop()
83         observer.join()
84
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zds/tutorialv2/management/commands/publication_watchdog.py b/zds/tutorialv2/management/commands/publication_watchdog.py
--- a/zds/tutorialv2/management/commands/publication_watchdog.py
+++ b/zds/tutorialv2/management/commands/publication_watchdog.py
@@ -30,7 +30,7 @@
             except Exception:
                 pass
         shutil.rmtree(extra_contents_path)
-        os.remove()
+        os.remove(watchdog_file_path)
 
     def __init__(self):
         self.prepare_callbacks = [TutorialIsPublished.__create_dir]

{"golden_diff": "diff --git a/zds/tutorialv2/management/commands/publication_watchdog.py b/zds/tutorialv2/management/commands/publication_watchdog.py\n--- a/zds/tutorialv2/management/commands/publication_watchdog.py\n+++ b/zds/tutorialv2/management/commands/publication_watchdog.py\n@@ -30,7 +30,7 @@\n             except Exception:\n                 pass\n         shutil.rmtree(extra_contents_path)\n-        os.remove()\n+        os.remove(watchdog_file_path)\n \n     def __init__(self):\n         self.prepare_callbacks = [TutorialIsPublished.__create_dir]\n", "issue": "[beta][v16][rc1] Les contenus extra (pdf, epub, etc.) ne sont pas g\u00e9n\u00e9r\u00e9s lors de la 2nde validation\nVersion 16 RC1.\n\nSc\u00e9nario de test : \n- Je publie un tutoriel pris en zone de validation (J'ai pris celui sur les bases de la prog)\n- Le tutoriel est r\u00e9serv\u00e9, publi\u00e9.\n- Je modifie le sous-titre du tutoriel et redemande sa validation (2 min apr\u00e8s la premi\u00e8re publication)\n- Je le r\u00e9server puis publie une fois de plus le tutoriel sans cocher la case maj majeur, donc en version mineure\n- Le tutoriel est publi\u00e9 cette fois, mais apr\u00e8s 5 min, toujours pas de signe d'un pdf ni epub, etc.\n\n", "before_files": [{"content": "# coding: utf-8\nfrom os.path import dirname, join\nimport os\nimport time\n\nimport shutil\nfrom django.core.management import BaseCommand\nfrom pathtools.path import listdir\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileCreatedEvent, FileSystemEventHandler, LoggingEventHandler\nfrom zds import settings\nfrom zds.tutorialv2.publication_utils import generate_exernal_content\nfrom codecs import open\n\n\nclass TutorialIsPublished(FileSystemEventHandler):\n    prepare_callbacks = []  # because we can imagine we will create far more than test directory existence\n    finish_callbacks = []  # because we can imagine we will send a PM on success or failure one day\n\n    @staticmethod\n    def __create_dir(extra_contents_path):\n        if not os.path.exists(extra_contents_path):\n                os.makedirs(extra_contents_path)\n\n    @staticmethod\n    def __cleanup_build_and_watchdog(extra_contents_path, watchdog_file_path):\n        for listed in listdir(extra_contents_path, recursive=False):\n            try:\n                shutil.copy(join(extra_contents_path, listed), extra_contents_path.replace(\"__building\", \"\"))\n            except Exception:\n                pass\n        shutil.rmtree(extra_contents_path)\n        os.remove()\n\n    def __init__(self):\n        self.prepare_callbacks = [TutorialIsPublished.__create_dir]\n        self.finish_callbacks = [TutorialIsPublished.__cleanup_build_and_watchdog]\n\n    def on_created(self, event):\n        super(TutorialIsPublished, self).on_created(event)\n        pandoc_debug_str = \"\"\n\n        if settings.PANDOC_LOG_STATE:\n            pandoc_debug_str = \" 2>&1 | tee -a \" + settings.PANDOC_LOG\n        if isinstance(event, FileCreatedEvent):\n            with open(event.src_path, encoding=\"utf-8\") as f:\n                infos = f.read().strip().split(\";\")\n            md_file_path = infos[1]\n            base_name = infos[0]\n            extra_contents_path = dirname(md_file_path)\n            self.prepare_generation(extra_contents_path)\n            try:\n                generate_exernal_content(base_name, extra_contents_path, md_file_path,\n                                         pandoc_debug_str, overload_settings=True)\n            finally:\n                self.finish_generation(extra_contents_path, event.src_path)\n\n    def prepare_generation(self, extra_contents_path):\n\n        for callback in self.prepare_callbacks:\n            callback(extra_contents_path)\n\n    def finish_generation(self, extra_contents_path, watchdog_file_path):\n        for callback in self.finish_callbacks:\n            callback(extra_contents_path, watchdog_file_path)\n\n\nclass Command(BaseCommand):\n    help = 'Launch a watchdog that generate all exported formats (epub, pdf...) files without blocking request handling'\n\n    def handle(self, *args, **options):\n        path = settings.ZDS_APP['content']['extra_content_watchdog_dir']\n        event_handler = TutorialIsPublished()\n        observer = Observer()\n        observer.schedule(event_handler, path, recursive=True)\n        observer.schedule(LoggingEventHandler(), path)\n        observer.start()\n        try:\n            while True:\n                time.sleep(1)\n        except KeyboardInterrupt:\n            observer.stop()\n        observer.join()\n", "path": "zds/tutorialv2/management/commands/publication_watchdog.py"}], "after_files": [{"content": "# coding: utf-8\nfrom os.path import dirname, join\nimport os\nimport time\n\nimport shutil\nfrom django.core.management import BaseCommand\nfrom pathtools.path import listdir\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileCreatedEvent, FileSystemEventHandler, LoggingEventHandler\nfrom zds import settings\nfrom zds.tutorialv2.publication_utils import generate_exernal_content\nfrom codecs import open\n\n\nclass TutorialIsPublished(FileSystemEventHandler):\n    prepare_callbacks = []  # because we can imagine we will create far more than test directory existence\n    finish_callbacks = []  # because we can imagine we will send a PM on success or failure one day\n\n    @staticmethod\n    def __create_dir(extra_contents_path):\n        if not os.path.exists(extra_contents_path):\n                os.makedirs(extra_contents_path)\n\n    @staticmethod\n    def __cleanup_build_and_watchdog(extra_contents_path, watchdog_file_path):\n        for listed in listdir(extra_contents_path, recursive=False):\n            try:\n                shutil.copy(join(extra_contents_path, listed), extra_contents_path.replace(\"__building\", \"\"))\n            except Exception:\n                pass\n        shutil.rmtree(extra_contents_path)\n        os.remove(watchdog_file_path)\n\n    def __init__(self):\n        self.prepare_callbacks = [TutorialIsPublished.__create_dir]\n        self.finish_callbacks = [TutorialIsPublished.__cleanup_build_and_watchdog]\n\n    def on_created(self, event):\n        super(TutorialIsPublished, self).on_created(event)\n        pandoc_debug_str = \"\"\n\n        if settings.PANDOC_LOG_STATE:\n            pandoc_debug_str = \" 2>&1 | tee -a \" + settings.PANDOC_LOG\n        if isinstance(event, FileCreatedEvent):\n            with open(event.src_path, encoding=\"utf-8\") as f:\n                infos = f.read().strip().split(\";\")\n            md_file_path = infos[1]\n            base_name = infos[0]\n            extra_contents_path = dirname(md_file_path)\n            self.prepare_generation(extra_contents_path)\n            try:\n                generate_exernal_content(base_name, extra_contents_path, md_file_path,\n                                         pandoc_debug_str, overload_settings=True)\n            finally:\n                self.finish_generation(extra_contents_path, event.src_path)\n\n    def prepare_generation(self, extra_contents_path):\n\n        for callback in self.prepare_callbacks:\n            callback(extra_contents_path)\n\n    def finish_generation(self, extra_contents_path, watchdog_file_path):\n        for callback in self.finish_callbacks:\n            callback(extra_contents_path, watchdog_file_path)\n\n\nclass Command(BaseCommand):\n    help = 'Launch a watchdog that generate all exported formats (epub, pdf...) files without blocking request handling'\n\n    def handle(self, *args, **options):\n        path = settings.ZDS_APP['content']['extra_content_watchdog_dir']\n        event_handler = TutorialIsPublished()\n        observer = Observer()\n        observer.schedule(event_handler, path, recursive=True)\n        observer.schedule(LoggingEventHandler(), path)\n        observer.start()\n        try:\n            while True:\n                time.sleep(1)\n        except KeyboardInterrupt:\n            observer.stop()\n        observer.join()\n", "path": "zds/tutorialv2/management/commands/publication_watchdog.py"}]}