def download(url, dest, expiry=None): # possible values of expiry: # 0: always download again # -1: never download again # <int>: download again when file is <int> seconds old if expiry is None: expiry = 60 * 60 * 24 * 14 getengine().run(Download(url, _homepath2real(dest), expiry))
def writefile(filename): stream = None try: stream = StringIO() yield stream stream.seek(0) getengine().run(WriteFile(_homepath2real(filename), stream.read())) finally: if stream: stream.close()
def symlink(target, linkname=None): # expand <target> to a path relative to the current repo target = _repopath2real(target, getrepoinfo().localrepo) # if [linkname] is omited, assume the symlink goes into $HOME/ at the top # level if linkname is None: linkname = os.path.join(os.environ.get('HOME'), os.path.basename(target)) else: linkname = _homepath2real(linkname) getengine().run(MakeSymlink(target, linkname))
def blockinfile(filename, lines, *args, **kwargs): if len(args) < 2: # handle the new call signature where = args[0] if len(args) else None prefix = kwargs.pop('prefix', None) suffix = kwargs.pop('suffix', None) assert not len(kwargs) else: # assume the old call signature used by my repos # TODO: remove this deprecated alternate call signature prefix, suffix = args where = kwargs.pop('where', None) assert not len(kwargs) filename = _homepath2real(filename) obj = BlockInFile(filename, lines, where, prefix, suffix) getengine().run(obj)
def section(func): name = func.__name__ engine = getengine() try: with entersection(":" + name + "()"): if engine.pushsection(name): func() finally: engine.popsection(name)
def pipinstall(packagename, pips=None, trypips=[], scripts=None): """ Install packages from pip. The primary advantage of using this function is that homely can automatically remove the package for you when you no longer want it. package: The name of the pip package to install pips: A list of `pip` executables to install the package with. `['pip2.7', 'pip3.4']` would install the package using both the `pip2.7` and `pip3.4` executables. The default is to use `['pip']` as long as you aren't using `trypips`. trypips: This is a supplementary list of `pip` executables that homely will use to install the package, but no exception will be raised if the `pip` executables aren't available. Note that the `pip install ...` commands are run with the `--user` option so that the packages are installed into your home directory. """ # `scripts` is an alternate location for bin scripts. Useful for bad # platforms that put pip2/pip3 scripts in the same bin dir such that they # clobber each other. # FIXME: `scripts` still has the following issues # - useless if you're specifying multiple pips at once # - won't do the uninstall/reinstall dance to reinstall something that was # installed with a different `scripts` path if scripts is None: scripts = {} if pips is None: pips = [] if len(trypips) else ['pip'] engine = getengine() for pip in pips: helper = PIPInstall(packagename, pip, mustinstall=True, scripts=scripts.get(pip)) engine.run(helper) for pip in trypips: helper = PIPInstall(packagename, pip, mustinstall=False, scripts=scripts.get(pip)) engine.run(helper)
def lineinfile(filename, contents, where=None): filename = _homepath2real(filename) obj = LineInFile(filename, contents, where) getengine().run(obj)
def mkdir(path): path = _homepath2real(path) getengine().run(MakeDir(path))
def installpkg(name, wantcmd=None, **methods): for key in methods: assert key in _METHODS # FIXME: make sure the user specifies at least one way to install the thing getengine().run(InstallPackage(name, methods, wantcmd))
def run(updatehelper): getengine().run(updatehelper)