예제 #1
0
파일: files.py 프로젝트: phodge/homely
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))
예제 #2
0
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()
예제 #3
0
파일: files.py 프로젝트: phodge/homely
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))
예제 #4
0
파일: files.py 프로젝트: phodge/homely
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)
예제 #5
0
def section(func):
    name = func.__name__
    engine = getengine()
    try:
        with entersection(":" + name + "()"):
            if engine.pushsection(name):
                func()
    finally:
        engine.popsection(name)
예제 #6
0
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)
예제 #7
0
파일: pipinstall.py 프로젝트: phodge/homely
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)
예제 #8
0
파일: files.py 프로젝트: phodge/homely
def lineinfile(filename, contents, where=None):
    filename = _homepath2real(filename)
    obj = LineInFile(filename, contents, where)
    getengine().run(obj)
예제 #9
0
파일: files.py 프로젝트: phodge/homely
def mkdir(path):
    path = _homepath2real(path)
    getengine().run(MakeDir(path))
예제 #10
0
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))
예제 #11
0
def run(updatehelper):
    getengine().run(updatehelper)
예제 #12
0
파일: install.py 프로젝트: phodge/homely
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))