def get_backup_fpaths(ibs): fname, ext = splitext(ibs.sqldb_fname) backups = sorted(ut.glob(ibs.backupdir, '*%s' % ext)) #backup_info = [ut.get_file_info(fpath) for fpath in backups] modified = [ut.get_file_info(fpath)['last_modified'] for fpath in backups] unixtimes = [ut.util_time.exiftime_to_unixtime(tag) for tag in modified] backups = ut.sortedby(backups, unixtimes) return backups #backup_uuids = [ut.get_file_uuid(fpath) for fpath in backups] #backup_hashes = [ut.get_file_hash(fpath) for fpath in backups] #backup_bytes = [ut.get_file_nBytes(fpath) for fpath in backups] pass
def total_purge_developed_repo(repodir): r""" Outputs commands to help purge a repo Args: repodir (str): path to developed repository CommandLine: python -m utool.util_sysreq total_purge_installed_repo --show Ignore: repodir = ut.truepath('~/code/Lasagne') Example: >>> # DISABLE_DOCTEST >>> from utool.util_sysreq import * # NOQA >>> import utool as ut >>> repodir = ut.get_argval('--repodir', default=None) >>> result = total_purge_installed_repo(repodir) """ assert repodir is not None import utool as ut import os repo = ut.util_git.Repo(dpath=repodir) user = os.environ['USER'] fmtdict = dict( user=user, modname=repo.modname, reponame=repo.reponame, dpath=repo.dpath, global_site_pkgs=ut.get_global_dist_packages_dir(), local_site_pkgs=ut.get_local_dist_packages_dir(), venv_site_pkgs=ut.get_site_packages_dir(), ) commands = [_.format(**fmtdict) for _ in [ 'pip uninstall {modname}', 'sudo -H pip uninstall {modname}', 'sudo pip uninstall {modname}', 'easy_install -m {modname}', 'cd {dpath} && python setup.py develop --uninstall', # If they still exist try chowning to current user 'sudo chown -R {user}:{user} {dpath}', ]] print('Normal uninstall commands') print('\n'.join(commands)) possible_link_paths = [_.format(**fmtdict) for _ in [ '{dpath}/{modname}.egg-info', '{dpath}/build', '{venv_site_pkgs}/{reponame}.egg-info', '{local_site_pkgs}/{reponame}.egg-info', '{venv_site_pkgs}/{reponame}.egg-info', ]] from os.path import exists, basename existing_link_paths = [path for path in possible_link_paths] print('# Delete paths and eggs') for path in existing_link_paths: if exists(path): if ut.get_file_info(path)['owner'] != user: print('sudo /bin/rm -rf {path}'.format(path=path)) else: print('/bin/rm -rf {path}'.format(path=path)) #ut.delete(path) print('# Make sure nothing is in the easy install paths') easyinstall_paths = [_.format(**fmtdict) for _ in [ '{venv_site_pkgs}/easy-install.pth', '{local_site_pkgs}/easy-install.pth', '{venv_site_pkgs}/easy-install.pth', ]] for path in easyinstall_paths: if exists(path): easy_install_list = ut.readfrom(path, verbose=False).strip().split('\n') easy_install_list_ = [basename(p) for p in easy_install_list] index1 = ut.listfind(easy_install_list_, repo.reponame) index2 = ut.listfind(easy_install_list_, repo.modname) if index1 is not None or index2 is not None: print('Found at index1=%r, index=%r' % (index1, index2)) if ut.get_file_info(path)['owner'] != user: print('sudo gvim {path}'.format(path=path)) else: print('gvim {path}'.format(path=path)) checkcmds = [_.format(**fmtdict) for _ in [ 'python -c "import {modname}; print({modname}.__file__)"' ]] import sys assert repo.modname not in sys.modules print("# CHECK STATUS") for cmd in checkcmds: print(cmd)
def total_purge_developed_repo(repodir): r""" Outputs commands to help purge a repo Args: repodir (str): path to developed repository CommandLine: python -m utool.util_sysreq total_purge_installed_repo --show Ignore: repodir = ut.truepath('~/code/Lasagne') Example: >>> # DISABLE_DOCTEST >>> from utool.util_sysreq import * # NOQA >>> import utool as ut >>> repodir = ut.get_argval('--repodir', default=None) >>> result = total_purge_installed_repo(repodir) """ assert repodir is not None import utool as ut import os repo = ut.util_git.Repo(dpath=repodir) user = os.environ['USER'] fmtdict = dict( user=user, modname=repo.modname, reponame=repo.reponame, dpath=repo.dpath, global_site_pkgs=ut.get_global_dist_packages_dir(), local_site_pkgs=ut.get_local_dist_packages_dir(), venv_site_pkgs=ut.get_site_packages_dir(), ) commands = [ _.format(**fmtdict) for _ in [ 'pip uninstall {modname}', 'sudo -H pip uninstall {modname}', 'sudo pip uninstall {modname}', 'easy_install -m {modname}', 'cd {dpath} && python setup.py develop --uninstall', # If they still exist try chowning to current user 'sudo chown -R {user}:{user} {dpath}', ] ] print('Normal uninstall commands') print('\n'.join(commands)) possible_link_paths = [ _.format(**fmtdict) for _ in [ '{dpath}/{modname}.egg-info', '{dpath}/build', '{venv_site_pkgs}/{reponame}.egg-info', '{local_site_pkgs}/{reponame}.egg-info', '{venv_site_pkgs}/{reponame}.egg-info', ] ] from os.path import exists, basename existing_link_paths = [path for path in possible_link_paths] print('# Delete paths and eggs') for path in existing_link_paths: if exists(path): if ut.get_file_info(path)['owner'] != user: print('sudo /bin/rm -rf {path}'.format(path=path)) else: print('/bin/rm -rf {path}'.format(path=path)) #ut.delete(path) print('# Make sure nothing is in the easy install paths') easyinstall_paths = [ _.format(**fmtdict) for _ in [ '{venv_site_pkgs}/easy-install.pth', '{local_site_pkgs}/easy-install.pth', '{venv_site_pkgs}/easy-install.pth', ] ] for path in easyinstall_paths: if exists(path): easy_install_list = ut.readfrom(path, verbose=False).strip().split('\n') easy_install_list_ = [basename(p) for p in easy_install_list] index1 = ut.listfind(easy_install_list_, repo.reponame) index2 = ut.listfind(easy_install_list_, repo.modname) if index1 is not None or index2 is not None: print('Found at index1=%r, index=%r' % (index1, index2)) if ut.get_file_info(path)['owner'] != user: print('sudo gvim {path}'.format(path=path)) else: print('gvim {path}'.format(path=path)) checkcmds = [ _.format(**fmtdict) for _ in ['python -c "import {modname}; print({modname}.__file__)"'] ] import sys assert repo.modname not in sys.modules print("# CHECK STATUS") for cmd in checkcmds: print(cmd)