Implement support for latest package format revision
This commit is contained in:
		
							parent
							
								
									79321791ac
								
							
						
					
					
						commit
						0e76413300
					
				
					 2 changed files with 23 additions and 1 deletions
				
			
		| 
						 | 
					@ -10,6 +10,7 @@ from core.services.WebServiceApiService import WebServiceApiService
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
from typing import Optional
 | 
					from typing import Optional
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import random
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import stat
 | 
					import stat
 | 
				
			||||||
| 
						 | 
					@ -34,10 +35,21 @@ class ApplicationController:
 | 
				
			||||||
        from core.controllers.ProfileController import ProfileController
 | 
					        from core.controllers.ProfileController import ProfileController
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        persistent_state_path = f'{profile.get_data_path()}/persistent-state'
 | 
					        persistent_state_path = f'{profile.get_data_path()}/persistent-state'
 | 
				
			||||||
 | 
					        font_path = f'{profile.get_data_path()}/fonts'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not os.path.isdir(persistent_state_path) or len(os.listdir(persistent_state_path)) == 0:
 | 
					        if not os.path.isdir(persistent_state_path) or len(os.listdir(persistent_state_path)) == 0:
 | 
				
			||||||
            shutil.copytree(f'{version.get_installation_path()}/resources/initial-state', persistent_state_path)
 | 
					            shutil.copytree(f'{version.get_installation_path()}/resources/initial-state', persistent_state_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (not os.path.isdir(font_path) or len(os.listdir(font_path)) == 0) and os.path.isdir('/usr/share/fonts/truetype'):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            font_families = [file.name for file in Path('/usr/share/fonts/truetype').iterdir() if file.is_dir()]
 | 
				
			||||||
 | 
					            preferred_font_families = ['dejavu', 'droid', 'liberation', 'libreoffice', 'noto', 'ubuntu']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            font_family_subset = ApplicationController.__select_random_subset(font_families, preferred_font_families, 12)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for font_family in font_family_subset:
 | 
				
			||||||
 | 
					                shutil.copytree(f'/usr/share/fonts/truetype/{font_family}', f'{font_path}/{font_family}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        display = ApplicationController.__find_unused_display()
 | 
					        display = ApplicationController.__find_unused_display()
 | 
				
			||||||
        time_zone = profile.determine_timezone()
 | 
					        time_zone = profile.determine_timezone()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,6 +122,16 @@ class ApplicationController:
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return ':170'
 | 
					            return ':170'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def __select_random_subset(items: list, preferred_items: list, limit: int):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        available_preferred_items = [item for item in preferred_items if item in items]
 | 
				
			||||||
 | 
					        selectable_items = [item for item in items if item not in preferred_items]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        selected_items = random.sample(selectable_items, random.randint(0, min(limit, len(selectable_items))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return selected_items + available_preferred_items
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def __run_process(initialization_file_path, profile, display, session_state):
 | 
					    def __run_process(initialization_file_path, profile, display, session_state):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +72,7 @@ class ApplicationVersion(Model):
 | 
				
			||||||
        return os.path.isdir(self.get_installation_path()) and len(os.listdir(self.get_installation_path())) > 0
 | 
					        return os.path.isdir(self.get_installation_path()) and len(os.listdir(self.get_installation_path())) > 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def is_supported(self):
 | 
					    def is_supported(self):
 | 
				
			||||||
        return self.exists(self.application_code, self.version_number) and self.format_revision == 1
 | 
					        return self.exists(self.application_code, self.version_number) and self.format_revision == 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_installed_file_hash(self):
 | 
					    def get_installed_file_hash(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue