I have a fabfile with:
env.user = 'deploy'
def infra():
"""You need to use a user that can root itself, deploy cannot without a
password."""
put('conf.d/etc/nginx/sites-available/www.foo.hk',
'/etc/nginx/sites-available/www.foo.hk', use_sudo=True)
sudo('nginx -s reload',)
Which I run like fab infra -Rservers.
So I thought I could override the user with --user=root or -u root when I run fab infra --user=root but it's still asking me for a password. However if I change env.user to env.user = 'root' it doesn't. I can also use the settings context manager like:
def infra(user):
"""You need to use a user that can root itself, deploy cannot without a
password."""
with settings(user=user):
put('conf.d/etc/nginx/sites-available/www.foo.hk',
'/etc/nginx/sites-available/www.foo.hk', use_sudo=True)
sudo('nginx -s reload',)
That works when I do fab infra:root -Rservers. So clearly it's possible to override the setting, but it seems like I can't from the normal command line flag. Am I doing something wrong?
It's not currently possible to override the default setting from the command line in the way I would want. There's a ticket for it though https://github.com/fabric/fabric/issues/680 and it seem like it will be fixed.
You've got a ticket open for this, I also showed the example there more like you showed here. My guess is you can't set env.user in the file beforehand as that's an explicit hardcoding.
I think you're looking for:
fab infra:hosts=root#somehost
It's unclear to me whether the same username#... pattern works with roles or roledefs.
http://docs.fabfile.org/en/1.2.0/usage/execution.html
Related
I am new in the Mercurial, and I am interested in the merging process. I would like to see how it happens programmatically, but something did not work out. I do not understand how to call the option, as we do it from the console using the hg merge --tool internal:fail command.
I did it like this
commands.merge(ui, repo, tool='internal:fail'),
but it still runs the default kdiff3.
I tried to do this
ui.setconfig('ui', 'merge', 'internal:fail')
commands.merge(ui, repo),
but it works like the previous one.
If someone understands what I'm doing wrong and how to fix it, please answer me.
Thank you for your attention to my question, have a good time =)
I managed to find the answer to my question, if someone needs it, look
We need to override the repository as follows:
def reposetup (ui, repo):
repo.ui.setconfig ('ui', 'merge', 'internal: fail') # or smth else, for example "merge3"
repo.ui.setconfig ('ui', 'interactive', 'no')
After this, the merge command will follow the configuration we defined =)
Have a local copy of Wiki (MediaWiki) but my predecessor left without handing over the password.
I got access to the server panel, and to mySQL, but despite I try to change the password as explained at https://www.mediawiki.org/wiki/Manual:Resetting_passwords I can't get it working.
In the localSetting.php file there is not a salt specified, which from ver 1.13 onward seems to be deprecated, but somehow my password have one.
E.g. :B:d1c1ee33:115272fdacb0ff5f6dcb3639d0bc08b3
Looking at the ./includes/User.php file, there is a crypt function that generate a random salt, so technically as long as I use a random name while using the following update statement I should be fine.
UPDATE `user` SET user_password = CONCAT(':B:somesalt:', MD5(CONCAT('somesalt-', MD5('somepass')))) WHERE user_name = 'someuser';
That's not the case. Anybody can help?
Use a maintenance script such as changePassword.php or createAndPromote.php.
I want to clear all data in my app. I used
python manage.py flush
It cleared all the questions I created but when I recreate other new questions, the question_id are still saved.
For example, the current question is "What is this?" with question_id=1. After using "flush" and creating new question "what is that?", this new question is marked as question_id=2 although there's no "What is this" question in the admin site.
How can I reset the question_id as well? It means that, after deleting or flushing data, the question_id must start counting again from 1.
Thank you.
You can use sqlsequencereset command to do that.
As per Django docs,
Use this command to generate SQL which will fix cases where a sequence
is out of sync with its automatically incremented field data.
Run the following command and you will see the list of reset commands you can use.
django-admin sqlsequencereset
If the app_name is specified, it prints the SQL statements for resetting sequences for the given app name(s).
python manage.py help sqlsequencereset # get help docs on terminal
I just set up the environment for an existing Django project, on a new Mac. I know for certain there is nothing wrong with the code itself (just cloned the repo), but for some reason, Django can't seem to retrieve data from the database.
I know the correct tables and data is in the db.
I know the codebase is as it should be.
I can make queries using the Django shell.
Django doesn't throw any errors despite the data missing on the web page.
I realize that it's hard to debug this without further information, but I would really appreciate a finger pointing me to the right direction. I can't seem to find any useful logs.
EDIT:
I just realized the problem lies elsewhere. Unfortunately I can't delete this post with the bounty still open.
Without seeing any code, I can only suggest some general advice that might help you debug your problem. Please add a link to your repository if you can or some snippets of your database settings, the view which includes the database queries etc...
Debugging the view
The first thing I would recommend is using the python debugger inside the view which queries the database. If you've not used pdb before, it's a life saver which allows you to set breakpoints in your Python script and then interactively execute code inside the interpreter
>>> import pdb
>>> pdb.set_trace()
>>> # look at the results of your queries
If you are using the Django ORM, the QuerySet returned from the query should have all the data you expect.
If it doesn't then you need to look into your database configuration in settings.py.
If it does, then you must might not be returning that object to the template? Unlikely as you said the code was the same, but double check the objects you pass with your HttpResponse object.
Debugging the database settings
If you can query the database using the project settings inside settings.py from the django shell it sounds unlikley that there is a problem with this - but like everything double check.
You said that you've set up a new project on a mac. What is on a different operating system before? Maybe there is a problem with the paths now - to make your project platform independent remember to use the os.path.join() method when working with file paths.
And what about the username and password details....
Debugging the template
Maybe your template is referencing the wrong object variable name or object attribute.You mentioned that
Django doesn't throw any errors despite the data missing on the web
page.
This doesn't really tell us much - to quote the Django docs -
If you use a variable that doesn’t exist, the template system will
insert the value of the TEMPLATE_STRING_IF_INVALID setting, which is
set to '' (the empty string) by default.
So to check all the variables available to your template, you could use the debug template tag
{{ debug }}
Probably even better though is to use the django-debugging-toolbar - this will also let you examine the SQL queries your view is making.
Missing Modules
I would expect this to raise an exception if this were the problem, but have you checked that you have the psycopg module on your new machine?
I want to allow my users to upload a CSV of contact data that will populate a a model called contacts. I have used django-csv-importer and this seems to work ok. However, I would like to use maybe something like celery so that users can upload and just forget about waiting ( at the moment it can take 5 minutes).
Are they any projects that do what django-csv-importer does but with celery integration part? If so could someone give me any example if there is a better way?
Many thanks.
Happily I've worked with the author of django-csv-importer, and can report there's a newer version in the form of django-adaptors (https://github.com/anthony-tresontani/django-adaptors), it's the same project but renamed, so it might have some new stuff.
As for your specific question, joshua's answer is correct. But if you want a ridiculously rich implementation complete with audit trails, take a look at this: http://codeinthehole.com/writing/use-models-for-uploads/
in tasks.py
from celery.task import task
#task
def import_csv(filename):
my_csv_list = MyCsvModel.import_data(data = open(filename))
...
Then just call import_csv.delay(filename) in your view.