def mk_menus(prefix, files, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ menu_files = [f for f in files if (f.lower().startswith('menu/') and f.lower().endswith('.json'))] if not menu_files: return elif basename(abspath(prefix)).startswith('_'): logging.warn("Environment name starts with underscore '_'. " "Skipping menu installation.") return try: import menuinst except: logging.warn("Menuinst could not be imported:") logging.warn(traceback.format_exc()) return for f in menu_files: try: menuinst.install(join(prefix, f), remove, prefix) except: stdoutlog.error("menuinst Exception:") stdoutlog.error(traceback.format_exc())
def main(): from optparse import OptionParser p = OptionParser( usage="usage: %prog [options] MENU_FILE", description="install a menu item") p.add_option('-p', '--prefix', action="store", default=sys.prefix) p.add_option('--remove', action="store_true") p.add_option('--version', action="store_true") opts, args = p.parse_args() if opts.version: sys.stdout.write("menuinst: %s\n" % menuinst.__version__) return for arg in args: menuinst.install(join(opts.prefix, arg), opts.remove, opts.prefix)
def mk_menus(remove=False, prefix=None, pkg_names=None, root_prefix=None): try: import menuinst except (ImportError, OSError): return if prefix is None: prefix = sys.prefix if root_prefix is None: root_prefix = sys.prefix menu_dir = join(prefix, 'Menu') if not os.path.isdir(menu_dir): return for fn in os.listdir(menu_dir): if not fn.endswith('.json'): continue if pkg_names is not None and fn[:-5] not in pkg_names: # skip when not in the list of menus to create # when installing, the pkg_names list is specified, otherwise not # and we don't skip to try to remove shortcuts continue shortcut = join(menu_dir, fn) try: menuinst.install(shortcut, remove, prefix=prefix, root_prefix=root_prefix) except Exception as e: out("Failed to process %s...\n" % shortcut) err("Error: %s\n" % str(e)) err("Traceback:\n%s\n" % traceback.format_exc(20)) else: out("Processed %s successfully.\n" % shortcut)
def mk_menus(prefix, files, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ # exclude all envs starting with '_' if basename(abspath(prefix)).startswith('_'): return menu_files = [f for f in files if f.lower().startswith('menu/') and f.lower().endswith('.json')] if not menu_files: return try: import menuinst except ImportError: return for f in menu_files: try: menuinst.install(join(prefix, f), remove, prefix) except: stdoutlog.error("menuinst Exception:") stdoutlog.error(traceback.format_exc())
def mk_menus(prefix, files, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ exclude_envs = ('_build', '_test') # Exclude all envs starting with... if basename(abspath(prefix)).lower().startswith(exclude_envs): return menu_files = [f for f in files if f.lower().startswith('menu/') and f.lower().endswith('.json')] if not menu_files: return try: import menuinst except ImportError: return for f in menu_files: try: menuinst.install(join(prefix, f), remove, prefix) except: stdoutlog.error("menuinst Exception:") stdoutlog.error(traceback.format_exc())
def install_windows(): """ Install start-menu icons on windows systems. """ import platform if platform.system() != 'Windows': raise Exception('Not a windows machine.') import os #import shutil import tempfile import myokit import myokit.pype import menuinst # Process template to get icon directory tdir = tempfile.mkdtemp() try: p = myokit.pype.TemplateEngine() source = os.path.join(myokit.DIR_DATA, 'install-win', 'menu.json') varmap = {'icons': os.path.join(myokit.DIR_DATA, 'gui')} output = os.path.join(tdir, 'menu.json') with open(output, 'w') as f: p.set_output_stream(f) p.process(source, varmap) del (p) # Install menuinst.install(output) print('Done') finally: #shutil.rmtree(tdir) pass
def mk_menus(remove=False, prefix=None): try: import menuinst except (ImportError, OSError): return if prefix is None: prefix = sys.prefix menu_dir = join(prefix, 'Menu') if not os.path.isdir(menu_dir): return pkg_names = [s.strip() for s in sys.argv[2:]] for fn in os.listdir(menu_dir): if not fn.endswith('.json'): continue if pkg_names and fn[:-5] not in pkg_names: continue shortcut = join(menu_dir, fn) try: menuinst.install(shortcut, remove, prefix=prefix) except Exception as e: out("Failed to process %s...\n" % shortcut) err("Error: %s\n" % str(e)) err("Traceback:\n%s\n" % traceback.format_exc(20)) else: out("Processed %s successfully.\n" % shortcut)
def install(): if sys.platform == "win32": # Windows if 'LIBRARY_PREFIX' in os.environ: condaEnv = os.environ['LIBRARY_PREFIX'] else: condaEnv = os.environ['CONDA_PREFIX'] + '/Library' menuinst.install('src/menuinst-win.json', prefix=condaEnv)
def test_create_and_remove_shortcut(self): nonadmin=os.path.join(sys.prefix, ".nonadmin") shortcut = os.path.join(menu_dir, "menu-windows.json") has_nonadmin = os.path.exists(nonadmin) for mode in ["user", "system"]: if mode=="user": open(nonadmin, 'a').close() menuinst.install(shortcut, remove=False) menuinst.install(shortcut, remove=True) if os.path.exists(nonadmin): os.remove(nonadmin) if has_nonadmin: open(nonadmin, 'a').close()
def test_create_and_remove_shortcut(self): nonadmin = os.path.join(sys.prefix, ".nonadmin") shortcut = os.path.join(menu_dir, "menu-windows.json") has_nonadmin = os.path.exists(nonadmin) for mode in ["user", "system"]: if mode == "user": open(nonadmin, 'a').close() menuinst.install(shortcut, remove=False) menuinst.install(shortcut, remove=True) if os.path.exists(nonadmin): os.remove(nonadmin) if has_nonadmin: open(nonadmin, 'a').close()
def mk_menus(remove=False): try: import menuinst except ImportError: return menu_dir = join(sys.prefix, 'Menu') if os.path.exists(menu_dir): for fn in os.listdir(menu_dir): if fn.endswith('.json'): shortcut = join(menu_dir, fn) try: menuinst.install(shortcut, remove) except Exception as e: out("Failed to process %s...\n" % shortcut) err("Error: %s\n" % str(e)) err("Traceback:\n%s\n" % traceback.format_exc(20)) else: out("Processed %s successfully.\n" % shortcut)
def make_menu(prefix, file_path, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ if not on_win: return elif basename(prefix).startswith('_'): log.warn("Environment name starts with underscore '_'. Skipping menu installation.") return try: import menuinst menuinst.install(join(prefix, win_path_ok(file_path)), remove, prefix) except: stdoutlog.error("menuinst Exception", exc_info=True)
def make_menu(prefix, file_path, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ if not on_win: return elif basename(prefix).startswith('_'): log.warn("Environment name starts with underscore '_'. Skipping menu installation.") return try: import menuinst menuinst.install(join(prefix, win_path_ok(file_path)), remove, prefix) except Exception: stdoutlog.error("menuinst Exception", exc_info=True)
def mk_menus(prefix, files, remove=False): if abspath(prefix) != abspath(sys.prefix): # we currently only want to create menu items for packages # in default environment return menu_files = [f for f in files if f.startswith('Menu/') and f.endswith('.json')] if not menu_files: return try: import menuinst except ImportError: return for f in menu_files: try: menuinst.install(join(prefix, f), remove, prefix) except: stdoutlog.error("menuinst Exception:") stdoutlog.error(traceback.format_exc())
def mk_menus(prefix, files, remove=False): if abspath(prefix) != abspath(sys.prefix): # we currently only want to create menu items for packages # in default environment return menu_files = [f for f in files if f.startswith('Menu/') and f.endswith('.json')] if not menu_files: return try: import menuinst except ImportError: return for f in menu_files: try: menuinst.install(join(prefix, f), remove, prefix) except: print("menuinst Exception:") traceback.print_exc(file=sys.stdout)
def mk_menus(prefix, files, remove=False): """ Create cross-platform menu items (e.g. Windows Start Menu) Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``. ``remove=True`` will remove the menu items. """ menu_files = [f for f in files if f.lower().startswith('menu/') and f.lower().endswith('.json')] if not menu_files: return elif basename(abspath(prefix)).startswith('_'): logging.warn("Environment name starts with underscore '_'. " "Skipping menu installation.") return try: import menuinst except: logging.warn("Menuinst could not be imported:") logging.warn(traceback.format_exc()) return env_name = (None if abspath(prefix) == abspath(sys.prefix) else basename(prefix)) # only windows is provided right now. Add "source activate" if on Unix platforms env_setup_cmd = "activate" if env_name: env_setup_cmd = env_setup_cmd + " %s" % env_name for f in menu_files: try: if menuinst.__version__.startswith('1.0'): menuinst.install(join(prefix, f), remove, prefix) else: menuinst.install(join(prefix, f), remove, root_prefix=sys.prefix, target_prefix=prefix, env_name=env_name, env_setup_cmd=env_setup_cmd) except: stdoutlog.error("menuinst Exception:") stdoutlog.error(traceback.format_exc())
def main(): from optparse import OptionParser p = OptionParser(usage="usage: %prog [options] MENU_FILE", description="install a menu item") p.add_option('-p', '--prefix', action="store", default=sys.prefix) p.add_option('--remove', action="store_true") p.add_option('--version', action="store_true") opts, args = p.parse_args() if opts.version: sys.stdout.write("menuinst: %s\n" % menuinst.__version__) return for arg in args: menuinst.install(join(opts.prefix, arg), opts.remove, opts.prefix)