Re: custom django-admin commands naming convention
cool thanks, Marwan On Wed, Mar 9, 2011 at 12:14 AM, creecodewrote: > Hello Marwan, > > I don't know if it's common but for my needs it's a must! :-) I have > several apps with custom management commands and I've taken to naming > the commands like... > > my_app_name_my_custom_management_command_name.py > > If find it easier to read the command name if I separate each word > with an underscore. The names are fairly long but I'm not typing them > into the terminal all that much. Mostly called from cron or pulled up > through my bash history. > > Toodle-looo.. > creecode > > On Mar 8, 12:02 am, Marwan Al-Sabbagh > wrote: > > > Our company has a number of teams > > developing different apps and I didn't want the naming of the commands to > be > > a mess. Are there any recommendations for naming conventions of the > > commands. Is it common for example to call the command appname_command to > > make it clear which app is implementing which command. Any > advice/experience > > is welcome. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: custom django-admin commands naming convention
Hello Marwan, I don't know if it's common but for my needs it's a must! :-) I have several apps with custom management commands and I've taken to naming the commands like... my_app_name_my_custom_management_command_name.py If find it easier to read the command name if I separate each word with an underscore. The names are fairly long but I'm not typing them into the terminal all that much. Mostly called from cron or pulled up through my bash history. Toodle-looo.. creecode On Mar 8, 12:02 am, Marwan Al-Sabbaghwrote: > Our company has a number of teams > developing different apps and I didn't want the naming of the commands to be > a mess. Are there any recommendations for naming conventions of the > commands. Is it common for example to call the command appname_command to > make it clear which app is implementing which command. Any advice/experience > is welcome. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
On Tue, Dec 22, 2009 at 3:24 PM, Bill Freemanwrote: > If you are calling this from, for example, crontab note that each line > in crontab is executed in its own subshell, so you have the choice of > setting PYTHONPATH, or (my personal favorite because it works with so > many kinds of scripts) you can cd to the project directory and execute > the script as ./manage.py custom, by separating the cd and ./manage.py > with a semicolon. Too, if you are doing this from a bash (or sh or, > probably, csh) script, commands run inside parentheses run in a sub > shell, so you can do the cd, semi, manage trick, and when the subshell > exits, the rest of your script is still running in its original > directory. Finally, if this is a command line utility that you want > to run from wherever and just have on the path, create a sh (or bash) > script that cd's and runs it instead, and put that on the path. This > last works on windows too, using bat files (or whatever the cmd.exe > equivalent is). > Thanks Bill, I'd considered that route, but ultimately, I had a puzzle that needed solving. =) ~Justin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
If you are calling this from, for example, crontab note that each line in crontab is executed in its own subshell, so you have the choice of setting PYTHONPATH, or (my personal favorite because it works with so many kinds of scripts) you can cd to the project directory and execute the script as ./manage.py custom, by separating the cd and ./manage.py with a semicolon. Too, if you are doing this from a bash (or sh or, probably, csh) script, commands run inside parentheses run in a sub shell, so you can do the cd, semi, manage trick, and when the subshell exits, the rest of your script is still running in its original directory. Finally, if this is a command line utility that you want to run from wherever and just have on the path, create a sh (or bash) script that cd's and runs it instead, and put that on the path. This last works on windows too, using bat files (or whatever the cmd.exe equivalent is). On Tue, Dec 22, 2009 at 5:59 AM, Justin Stewardwrote: > I'm at a loss as to understand why, but I've worked out what I need to > add to pythonpath. > > PYTHONPATH=/home/user > > i.e. The pythonpath needs to include NOT the project's root, but the > directory one level ABOVE that for custom commands to work properly... > > Thanks for the help guys. > > ~Justin > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
I'm at a loss as to understand why, but I've worked out what I need to add to pythonpath. PYTHONPATH=/home/user i.e. The pythonpath needs to include NOT the project's root, but the directory one level ABOVE that for custom commands to work properly... Thanks for the help guys. ~Justin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
On Tue, Dec 22, 2009 at 3:51 PM, Alex_Gaynorwrote: > > Do you have __init__.py files in each of those directories? Of course - Else it woud not work from the project's root directory either. ~Justin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
On Dec 21, 8:38 pm, Justin Stewardwrote: > On Tue, Dec 22, 2009 at 12:16 PM, Doug Blank wrote: > > > You probably just need to set your PYTHONPATH: > > > cd /home/user > > PYTHONPATH=proj python proj/manage.py custom > > That was my initial thought too, however setting the PYTHONPATH does > not affect the behaviour in this instance. > > ~Justin Do you have __init__.py files in each of those directories? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
On Tue, Dec 22, 2009 at 12:16 PM, Doug Blankwrote: > > You probably just need to set your PYTHONPATH: > > cd /home/user > PYTHONPATH=proj python proj/manage.py custom > That was my initial thought too, however setting the PYTHONPATH does not affect the behaviour in this instance. ~Justin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom Django-Admin commands
On Mon, Dec 21, 2009 at 8:10 PM, Justin Stewardwrote: > Hi all, > > I've written a custom command to use with manage.py, and from the root > of the project directory, it works great. > > But the problem is, this command is almost never going to be called > from within the project directory. > > (hoping the spacing doesn't get too mangled when I send this) > /home/ > user/ <- ""/home/user/proj/manage.py custom" command doesn't exist. > proj/ <- "/home/user/proj/manage.py custom" works > manage.py > app/ > management/ > commands/ > custom.py > > Is there something I'm missing? You probably just need to set your PYTHONPATH: cd /home/user PYTHONPATH=proj python proj/manage.py custom -Doug > > ~Justin > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom django-admin commands help?
Thanks Daniel, your guess was correct Id left out the handle stuff competely. It appears to be working perfectly now! Phil On 22 Feb, 13:21, Daniel Rosemanwrote: > On Feb 22, 1:00 pm, "phyl.jack...@gmail.com" > wrote: > > > > > I have a little custom script that changes some database stuff and > > sends an email - I want to set it to run on a cron job. > > > So Ive been trying to set it up as a custom django-admin command, Ive > > been trying to use this little bit of info- > > >http://docs.djangoproject.com/en/dev/howto/custom-management-commands... > > > I cannot get it tor work. Ive made the dir struture it suggests and it > > is finding my python file, Im just not sure how to structure it. I > > have this in an update.py file- > > > from django.core.management.base import BaseCommand > > import os > > import sys > > > class Command(BaseCommand): > > #--my script-- > > > The error I get is a NotImplementedError. I know it is reading the > > stuff in place of #--my script-- because it was giving me specific > > errors related to my script until I fixed them all. I try just putting > > something simple in place of #--my script-- like x=1 and it still > > gives me that NotImplementedError. Am I doing this right? What should > > my update.py file look like? > > > Thanks for any help! > > Phil > > You've cunningly cut out from the code you posted the actual contents > of the Command class, which is the bit that would enable us to > diagnose the problem. But at a guess, you have just put the script > directly under the class. It actually needs to go into a method called > 'handle', which is what is called when the command is run. Without > that method, Django is calling the method in the base class, which > raises NotImplementedError to tell you you need to override it. > > class Command(BaseCommand): > help = """Removes doubled up HTML classes caused by a TinyMCE > problem""" > > def handle(self, *args, **options): > ... script goes here... > > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom django-admin commands help?
On Feb 22, 1:00 pm, "phyl.jack...@gmail.com"wrote: > I have a little custom script that changes some database stuff and > sends an email - I want to set it to run on a cron job. > > So Ive been trying to set it up as a custom django-admin command, Ive > been trying to use this little bit of info- > > http://docs.djangoproject.com/en/dev/howto/custom-management-commands... > > I cannot get it tor work. Ive made the dir struture it suggests and it > is finding my python file, Im just not sure how to structure it. I > have this in an update.py file- > > from django.core.management.base import BaseCommand > import os > import sys > > class Command(BaseCommand): > #--my script-- > > The error I get is a NotImplementedError. I know it is reading the > stuff in place of #--my script-- because it was giving me specific > errors related to my script until I fixed them all. I try just putting > something simple in place of #--my script-- like x=1 and it still > gives me that NotImplementedError. Am I doing this right? What should > my update.py file look like? > > Thanks for any help! > Phil You've cunningly cut out from the code you posted the actual contents of the Command class, which is the bit that would enable us to diagnose the problem. But at a guess, you have just put the script directly under the class. It actually needs to go into a method called 'handle', which is what is called when the command is run. Without that method, Django is calling the method in the base class, which raises NotImplementedError to tell you you need to override it. class Command(BaseCommand): help = """Removes doubled up HTML classes caused by a TinyMCE problem""" def handle(self, *args, **options): ... script goes here... -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---