def _create_advanced_group(self, parent, show_title=True): title = 'Advanced' if show_title else None advanced = controls.create_control_group(parent, title, True) grid = GridLayouter(2) log.i("lnp.df_info.variations=".join(lnp.df_info.variations)) if 'legacy' not in lnp.df_info.variations: if 'twbt' in lnp.df_info.variations: grid.add(controls.create_trigger_option_button( advanced, 'Install TWBT Folders', 'If graphics pack includes TWBT folders install them.', self.toggle_insttwbt, 'insttwbt', lambda v: ('NO', 'YES')[ lnp.userconfig.get_value('insttwbt', True)]), 2) grid.add(controls.create_option_button( advanced, 'Print Mode', 'Changes how Dwarf Fortress draws to the screen. "2D" allows ' 'Truetype fonts, "standard" enables advanced graphics tools. ' 'Certain modifications may use other values.', 'printmode'), 2) grid.add(controls.create_option_button( advanced, 'TrueType Fonts', 'Toggles whether to use TrueType fonts or tileset for text. ' 'Only works with Print Mode set to 2D.', 'truetype'), 2) grid.add(controls.create_trigger_button( advanced, 'Simplify Graphic Folders', 'Deletes unnecessary files from graphics packs ' '(saves space, useful for re-packaging)', self.simplify_graphics)) return advanced
def fix(self, description): if len(description) < 2: log.w( "Nothing can be done automatically, the description is too short" ) else: if not self.full_stop: description += '.' log.i("Full stop has been added at the end") if not self.capital: description = description[0].upper() + description[1:] log.i("First letter has been converted to uppercase") self.pkg.manifest['metadata']['description'] = description self.write_pkg_manifest()
def open_shell(path): args = core.args.get_args() if args.visual: ret = os.system(f'xdg-open {path}') if ret == 0: return else: log.w( "A problem occured while using xdg-open, falling back on opening a shell" ) shell = os.environ.get('SHELL') if shell is None: log.w("No $SHELL environment variable found") shell = log.q("Please provide a valid shell: ") log.i(f"Opening {shell} in {path}, press CTRL-D to exit and resume checks") os.system(f'cd {path} && {shell}')
def open_editor(filepath): args = core.args.get_args() if args.visual: editor = os.environ.get('VISUAL') if editor is None: log.w("No $VISUAL environment variable found, trying $EDITOR") editor = os.environ.get('EDITOR') if editor is None: log.w("No $EDITOR environment variable found") editor = log.q("Please provide a valid editor: ") else: editor = os.environ.get('EDITOR') if editor is None: log.w("No $EDITOR environment variable found") editor = log.q("Please provide a valid editor: ") log.i(f"Opening {filepath} with {editor}") os.system(f'{editor} {filepath}')
def run(self): with log.push(), core.pushd(core.args.get_args().cache_dir): for item in self.items: if not self.validate(item): with log.push(): self.show(item) if Check.global_state is Type.FIX: self.fix(item) elif Check.global_state is Type.DIFF: self.diff(item) elif Check.global_state is Type.EDIT: log.i("The automatic changes would be as follows") with log.push(): if self.diff(item) is not False: answer = utils.ask_yne( "Accept those changes?") if answer is utils.Answer.YES: self.fix(item) elif answer == utils.Answer.EDIT: self.edit(item) else: if utils.ask_yn("Edit manually?"): self.edit(item)
def diff(self, description): if not self.capital: log.i("The first letter would be converted to uppercase") if not self.full_stop: log.i("A full stop would be added at the end")
def diff(self, item): log.i("X permissions would be added")
def fix(self, item): perms = os.stat(item).st_mode log.i(f"'{item}' has been given execute permissions") os.chmod(item, perms | stat.S_IXOTH | stat.S_IXGRP | stat.S_IXUSR)
def validate(self, item): log.i(f"Checking {item}") return os.access(item, os.X_OK)