Exemple #1
0
 def test_multiple_projects(self):
     """ Populates the ResourceContainer object and verifies the output."""
     # test with the English OBS
     zip_file = os.path.join(self.resources_dir,
                             'en-ta-multiple-projects.zip')
     self.out_dir = tempfile.mkdtemp(prefix='Door43_test_repo_')
     unzip(zip_file, self.out_dir)
     repo_dir = os.path.join(self.out_dir, 'en_ta')
     rc = RC(directory=repo_dir)
     rc.as_dict()
     yaml = load_yaml_object(os.path.join(repo_dir, 'manifest.yaml'))
     self.assertEqual(rc.resource.identifier,
                      yaml['dublin_core']['identifier'])
     self.assertEqual(rc.resource.type, yaml['dublin_core']['type'])
     self.assertEqual(rc.resource.format, yaml['dublin_core']['format'])
     self.assertEqual(rc.resource.file_ext, 'md')
     self.assertEqual(rc.resource.conformsto,
                      yaml['dublin_core']['conformsto'])
     self.assertEqual(rc.resource.modified, yaml['dublin_core']['modified'])
     self.assertEqual(len(rc.project_ids), 4)
     self.assertEqual(rc.project_count, 4)
     chapters = rc.project('checking').chapters()
     self.assertEqual(len(chapters), 44)
     chunks = rc.project('checking').chunks('level1')
     self.assertEqual(chunks, ['01.md', 'sub-title.md', 'title.md'])
     self.assertTrue('acceptable' in rc.project('checking').config())
     self.assertTrue('title' in rc.project('checking').toc())
     self.assertTrue(
         rc.project('checking').toc()['title'], 'Table of Contents')
 def get_manifest_from_dir(self) -> Dict[str, Any]:
     AppSettings.logger.info(f"get_manifest_from_dir() with {self.path} …")
     manifest = None
     self.loadeded_manifest_file = False
     if not self.path or not os.path.isdir(self.path):
         return get_manifest_from_repo_name(self.repo_name)
     try:
         manifest = load_yaml_object(
             os.path.join(self.path, 'manifest.yaml'))
     except (ParserError, ScannerError) as e:
         err_msg = f"Badly formed 'manifest.yaml' in {self.repo_name}: {e}"
         AppSettings.logger.error(err_msg)
         self.error_messages.add(err_msg)
     if manifest:
         self.loadeded_manifest_file = True
         return manifest
     try:
         manifest = load_json_object(
             os.path.join(self.path, 'manifest.json'))
     except JSONDecodeError as e:
         err_msg = f"Badly formed 'manifest.json' in {self.repo_name}: {e}"
         AppSettings.logger.error(err_msg)
         self.error_messages.add(err_msg)
     if manifest:
         self.loadeded_manifest_file = True
         return manifest
     try:
         manifest = load_json_object(os.path.join(self.path,
                                                  'package.json'))
     except JSONDecodeError as e:
         err_msg = f"Badly formed 'package.json' in {self.repo_name}: {e}"
         AppSettings.logger.error(err_msg)
         self.error_messages.add(err_msg)
     if manifest:
         self.loadeded_manifest_file = True
         return manifest
     try:
         manifest = load_json_object(os.path.join(self.path,
                                                  'project.json'))
     except JSONDecodeError as e:
         err_msg = f"Badly formed 'project.json' in {self.repo_name}: {e}"
         AppSettings.logger.error(err_msg)
         self.error_messages.add(err_msg)
     if manifest:
         self.loadeded_manifest_file = True
         return manifest
     try:
         manifest = load_json_object(os.path.join(self.path, 'meta.json'))
     except JSONDecodeError as e:
         err_msg = f"Badly formed 'meta.json' in {self.repo_name}: {e}"
         AppSettings.logger.error(err_msg)
         self.error_messages.add(err_msg)
     if manifest:
         self.loadeded_manifest_file = True
         return manifest
     return get_manifest_from_repo_name(self.repo_name)
Exemple #3
0
 def toc(self, project_identifier=None):
     p = self.project(project_identifier)
     if p is None:
         return None
     if not p.toc_yaml:
         file_path = os.path.join(self.path, p.path, 'toc.yaml')
         try:
             p.toc_yaml = load_yaml_object(file_path)
         except (ParserError, ScannerError) as e:
             err_msg = f"Badly formed 'toc.yaml' in {self.repo_name}: {e}"
             self.error_messages.add(err_msg)
     return p.toc_yaml
 def config(self, project_identifier=None):
     p = self.project(project_identifier)
     if p is None:
         return None
     if not p.config_yaml:
         file_path = os.path.join(self.path, p.path, 'config.yaml')
         try:
             p.config_yaml = load_yaml_object(file_path)
         except (ParserError, ScannerError) as e:
             err_msg = f"Badly formed 'config.yaml' in {self.repo_name}: {e}"
             AppSettings.logger.error(err_msg)
             self.error_messages.add(err_msg)
     return p.config_yaml
Exemple #5
0
 def test_en_obs_manifest_yaml(self):
     """ Populates the ResourceContainer object and verifies the output."""
     # test with the English OBS
     zip_file = os.path.join(self.resources_dir, 'en-obs-manifest-yaml.zip')
     self.out_dir = tempfile.mkdtemp(prefix='Door43_test_repo_')
     unzip(zip_file, self.out_dir)
     repo_dir = os.path.join(self.out_dir, 'en_obs')
     rc = RC(directory=repo_dir, repo_name='en_obs')
     rc_dic = rc.as_dict()
     yaml = load_yaml_object(os.path.join(repo_dir, 'manifest.yaml'))
     self.assertDictEqual(yaml, rc_dic)
     chapters = rc.projects[0].chapters()
     self.assertEqual(len(chapters), 2)
     chunks = rc.project().chunks('front')
     self.assertEqual(chunks, ['intro.md', 'title.md'])
 def build_page_nav(self, filename:Optional[str]=None) -> str:
     self.section_container_id = 1
     html = """
         <nav class="hidden-print hidden-xs hidden-sm content-nav" id="right-sidebar-nav">
             <ul class="nav nav-stacked">
     """
     for fname in self.HTMLfilepaths:
         # with open(fname, 'r') as f:
         #     soup = BeautifulSoup(f.read(), 'html.parser')
         # if soup.select('div#content h1'):
         #     title = soup.select('div#content h1')[0].text.strip()
         #     print(f"Got title1='{title}'")
         # else:
         title = os.path.splitext(os.path.basename(fname))[0].title()
         #     print(f"Got title2='{title}'")
         if title in self.NO_NAV_TITLES:
             continue
         if fname != filename:
             html += f"""
             <h4><a href="{os.path.basename(fname)}">{title}</a></h4>
             """
         else:
             html += f"""
             <h4>{title}</h4>
             """
             filepath = f'{os.path.splitext(fname)[0]}-toc.yaml'
             try:
                 toc = load_yaml_object(filepath)
             except (ParserError, ScannerError) as e:
                 err_msg = f"Templater found badly formed '{os.path.basename(filepath)}': {e}"
                 AppSettings.logger.critical("ObsNotes"+err_msg)
                 self.error_messages.add(err_msg)
                 toc = None
             if toc:
                 for section in toc['sections']:
                     html += self.build_section_toc(section)
             html += """
             """
     html += """
             </ul>
         </nav>
     """
     return html
Exemple #7
0
 def manifest(self):
     if not self._manifest and self.repo_dir:
         self._manifest = load_yaml_object(
             os.path.join(self.repo_dir, 'manifest.yaml'))
     return self._manifest