Comments (8)
Yes, I've been thinking about adding this kind of layer.
One issue that we need to address is that package names may vary from one distro to another. See the implementation of require.git.command() for example.
I'd like the API to keep the common case simple, but allow the user to override the default package name with alternate names for given distros / families. Something like:
# Simple case
require.system.package('python-dev')
# System-specific overrides
require.system.package('git', debian='git-core', sun='scmgit-base')
For installing multiple packages, each list item could be either a string or a dictionary, but it's not as pretty:
require.system.packages([
'curl',
'python-dev',
{'default': 'git', 'debian': 'git-core', 'sun': 'scmgit-base'},
])
from fabtools.
The same concept with less magic:
def choose_by_distrib_family(default, **kwargs):
return dict(**kwargs).get(distrib_family(), default)
# Simple case
require.system.package(
choose_by_distrib_family('git', debian='git-core', sun='scmgit-base'))
# multiple packages
require.system.packages([
'curl',
'python-dev',
choose_by_distrib_family(default='git', debian='git-core', sun='scmgit-base'),
])
from fabtools.
Nice! Make it shorter maybe (by_distrib_family
)?
from fabtools.
Also, we may want to cache the result of distrib_family()
...
from fabtools.
Most of the functions in system.py can be cached, but this should be a new ticket.
This could be implemented using memoization.
Original code:
http://stackoverflow.com/questions/1988804/what-is-memoization-and-how-can-i-use-it-in-python
Modified with env.host
def memoize(fn):
"""returns a memoized version of any function that can be called
with the same list of arguments.
Usage: foo = memoize(foo)"""
def foo(*args, **kwargs):
items = tuple(sorted(kwargs.items()))
if (args, items, env.host) not in foo.past_calls:
foo.past_calls[(args, items, env.host)] = fn(*args,**kwargs)
return foo.past_calls[(args, items, env.host)]
foo.past_calls = dict([])
foo.__name__ = 'memoized_' + fn.__name__
return foo
@memoize
def distrib_family():
"""
"""
from fabtools.
Where does this stand? I've created something similar in my tree.
Also, memoize cache would need to be cleared for each host change. e.g.,
fab -H centos_host, debian_host deploy
from fabtools.
I didn't implemented it yet.
from fabtools.
no news ? I was thinking, something like a json file with a map between package canonical name and its name in the different OS would be awesome. When doing a require.package, fabtools would check in the file if the package in present, and use the package name.
The file would be bundled with fabtools with a name like packages_name_map.json, and the user could override it in various ways. Thanks to the json format, to change it or correct it, even a no-programmer can edit it.
For git, it would be:
[ {"git": {"debian": "git-core", "sun" : "git-scm", "gentoo": "git-scm"}}]
from fabtools.
Related Issues (20)
- centos 7 support - fabtools.require.rpm.repository('epel') fails
- feature request: with fabtools.python.version(3.4): do smth HOT 2
- install_pip or package fails on centos 7 with sudo config setting <Defaults requiretty> HOT 3
- fabtools.require.python.virtualenv() is installing wheel from sources?
- Travis Tests?
- require tries to create home dir even if create_home is False
- mysql.query does not allow the use of --defaults-file
- Redis v3.2.x require fails because of binary rename
- fix md5sum in files.py
- require.oracle_jdk.installed fails due to change in Oracle download URL
- Issue while installing fabtools3 inside a container. HOT 1
- Fabric v2 support HOT 3
- sudo will fail when checking Postgres user
- systemd and supervisor processes can freeze due to pager HOT 1
- Update setup.py to pull fabric3 for Python 3
- `fabtools.files.mode` does not work properly with character expansion HOT 3
- `fabtools.require.files.file` mode type HOT 1
- error on add_ssh_public_key HOT 2
- how pytest run ?
- Fix simple typo: occured -> occurred
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fabtools.