how do i debug/breakpoint my django app using pycharm? - django

I'm trying to work out how to run the debug stuff that pycharm seems to offer (well, it allows me to set breakpoints, anyway, so i'm assuming there's a nice gui for it)
I've concluded that i cannot use the ctrl-shift-r and then "runserver" command, and that instead i'd need to setup a "run configuration"? I made a "django server" one, but i don't know what values to put etc. When i run it, it tells me that some setting is wrong - i'm pretty sure it isn't, because the standard "runserver" command works fine.
And that's about all i concluded. If there is a nifty tutorial or steps to get it so i can
put in a break point
go to the page that triggers that breakpoint and follow the code's inner working in pycharm
i'd be thrilled!
cheers!
UPDATE: in case you're wondering, here is the error i got:
Traceback (most recent call last):
File "manage.py", line 11, in
import settings
File "C:\development\PycharmProjects\dumpstown\settings.py", line 185, in
add_to_builtins('gravatar.templatetags.gravatar')
File "C:\development\python\lib\site-packages\django\template\base.py", line 1017, in add_to_builtins
builtins.append(import_library(module))
File "C:\development\python\lib\site-packages\django\template\base.py", line 963, in import_library
raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))
django.template.base.InvalidTemplateLibrary: ImportError raised loading gravatar.templatetags.gravatar: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Where the application itself, on a "runserver" never has any issues.
UPDATE: as per my answer below, pycharm is broken for add_to_builtins.

The problem has little to do with DJANGO_SETTINGS_MODULE. Pycharm sets this when creating the project. Instead Go to the little green "Play button" for running scripts. You want to configure it to run manage.py, ie you are configuring the play button to run the command python manage.py runserver.
Breakdown:
python------> run with python Intepreter
manage.py--------> run this script
runserver---------> arguments
So go to the drop down to the left of the green play button
,
click on edit configurations. You will get a screen like this one
.
Fill it out as shown locating your manage.py source script. Make sure you include runserver on the arguments box. Now you can click the green debug button and you program will stop at the first breakpoint it ecounters allowing you to descend upon it in full debug mode watch variables and all. Now you can manually type python manage.py runserver on the terminal or use your newley configured run button.

Setup your virtual environment
Create or open your project in PyCharm
Go to File - Settings in the menu (or just click on the settings icon)
Go to Python Interpreter
Click on Add in the top
Go to the bin folder where you created the virtual environment and select python
Set a breakpoint
Next to the line of code you want to set the breakpoint. To the left there is usually a grey line. Usually next to the line numbers. Just click there and a big red dot will appear. Looks like this
Hit the Run in debug mode button.
Next to the Green play button there is a button with a bug on it. Use that to launch the runserver in debug mode. Now when you use your web application and the code hits the breakpoint it will stop there and you will be able to step in and over or resume in pycharm.
If you still are not able to debug you might need to edit the pycharm project config. You can do that like this.
You can look at http://garmoncheg.blogspot.it/2012/01/establishing-dev-environment-with.html too

So i gave all the answers here a +1 for trying - but they're not the issue. Near as i can tell, the answer is that pycharm is broken. Which is a pain, but the solution is easy -
IF you dont' want to use the little green button at the top of pycharm, or use the pycharm debugging feature? then don't worry, you don't need to do anything. Continue using ctrl-shift-r and runserver (or whatever your shortcut to manage.py is)
IF you do want to use the little green "run" button, or if you want to use pycharm's debugging kit, then you absolutely cannot use the "add_to_builtins", at least in the settings.py file (I never put it anywhere else myself, pycharm might require it elsewhere?). add_to_builtins doesn't work in pycharm - it gets itself caught in a loop of grave consequences when you use the little green button or the debug button. Using ctrl-shift-r and runserver doesn't, curiously, have this problem.
The good news is that "add_to_builtins" isn't a must-have, just a nice-to-have. Just add the "{% load x %}" command to each template where you use x and you will be set.
Alternatively, save a hundred bucks and use some sort of free eclipse tool.

The problem is that the DJANGO_SETTINGS_MODULE variable which should point to your project's settings file, wasn't set anywhere, since the variable is reported to be undefined.
The solution and an explanation you can refer to can be found in a previous post

Related

How / Where can I see all TSLint errors for current project in WebStorm?

May be I am missing something but I have not found a dedicated place in WebStorm where I can see (and navigate) all errors reported by TSLint.
In the best case I can find the errors while opening a file and pressing F2 (to go to Next Highlighted Error) which not always working as well.
PS. There is a dedicated TypeScript Pane/l in WebStorm but it doesn't show any TSLint errors, neither these reported in Event Log Pane/l.
Select npm tab from the bottom left side.
Run linting script (you must have it in package.json).
See screenshot below for example:
List of tslint errors/warnings

Is it possible to suppress MessageBox when running a specific command?

I'm using Tortoise SVN, and TortoisePlink for remote ssh connections.
From time to time TortoisePlink is displaying errors like:
---------------------------
TortoisePlink Fatal Error
---------------------------
Network error: Software caused connection abort
---------------------------
OK
---------------------------
And they appears as messagebox and needs to be clicked by end-user.
I have tried to suppress messagebox by using -batch from command line, but problem still can be reproduced. For me it's sufficient if I'll disable messagebox prompting and print for example in command line same information - since my batch will retry later on again automatically.
Does there exists such software which can override default windows behavior and print in console window whatever is displayed in message box.
I guess in simplest terms such command line tool can be easily created, using for example
http://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra
and override MessageBoxA / MessageBoxW - but have anyone done this kind of thing ?
I think you're going about this the wrong way. Instead of trying to suppress the dialog boxes that TortoisePlink is showing, use the original Plink. TortoisePlink is a fork of Plink to explicitly show message boxes and not print anything on a command line, because it's designed for an UI app and not for console apps.
And if you really only want to use svn from a batch file, don't use TortoiseSVN but the original svn command line client (can be installed with the TSVN installer as well) and use the 'svn' command from the command line.
TortoisePLink.exe is targetted for end-user - so it's intended to display message boxes, however - there also exists a command line version of PLink.exe, and it can be downloaded from here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Please notice that "TortoiseSVN" > "Settings" > "Network" > "SSH Client" should use TortoisePLink.exe - errors will be displayed to end-user.
For following file however -
%appdata%\Subversion\
file ‘config’:
In section [tunnels]
Add line like this:
ssh = Plink.exe -l <your login> -pw <password>
You should use command line version of PLink.exe (that is also displaying command prompt when launched).
It's easier to save PLink.exe next with TortoisePLink.exe, that is into
C:\Program Files\TortoiseSVN\bin.
I have tried to make a command line tool for supressing messageboxes, but it's useless for TortoisePLink.exe (Haven't debugged what is the problem), but in case if you're interested (Have other means to use it):
https://sourceforge.net/p/diagnostic/svn/HEAD/tree/Tools/msgboxSupress/
msSupress.cpp is compiled into .dll and it uses minimalistic hook for windows to disable MessageBoxA and MessageBoxW - actually they will be printed to console or redirected to file.
msSupressExe.cpp is compiled into .exe and it starts process in suspended mode, replaces .exe's entry point with EB FE (jump short into itself), waits until that address is reached, injects .dll and .dll will hook new process.
I have tested only on 64-bit platform - I suspect that command being executed must match same platform as as msSupress.exe.
So typically TortoisePlink.exe will display messagebox - but when executed like this:
mbSupress.exe "C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe"
Same stuff as shown over message box will be displayed in console.
I think this solution is good prototype for further virus or trojan construction - using technique like this will allow to intercept even keyboard presses on any application - but I now made a command line utility, not a virus.

PyCharm - colored output in django console

The problem is that when I'm lauching dev-server through Kubuntu's Konsole app, debug output is colored:
But wher I'm launching it trough built-in "Run" or "Debug" in PyCharm, the output in PyCharm's console is all red:
Is there a way to make output in PyCharm colored? Because I can't find anything related in Settings.
UPD: link to issue on PyCharm issue tracker
As I see some people woting on this question, so here is the link to this issue on PyCharm issue tracker - youtrack.jetbrains.com/issue/PY-19790. If you will vote for this feature, it will be released faster!
Some time ago I wrote a code snippet that does the thing for me. It's not a perfect solution, but does the trick. BSD License
To use it:
Option 1: git clone/download this and import it somewhere (e.g. django development settings). Read the module docstring and the readme for details.
Option 2: include the code snippet below into your django development/debug settings (or anywhere else, where it will be run early). It's automatically verified with SHA-2 against file changes.
try: # Colored logger CaaS. Auto downloaded and verified.
import os
import hashlib
from urllib import request
url, sha256 = "https://lab.it.hs-hannover.de/lukyanch/pydevutils/raw/c531eaf7/colored_logger.py", "083e1a39cfdbe17a7126188b5477fb8f324be8106a39ed4a00faeb3f18c5aedc"
cached_file = "/tmp/{0}.py".format(sha256)
code = bool(os.path.exists(cached_file) or [request.urlretrieve(url, cached_file), print("Downloaded: " + url)]) and open(cached_file, "r").read()
assert hashlib.sha256(code.encode()).hexdigest() == sha256, os.remove(cached_file) or "Bad content: " + cached_file
exec(code)
except Exception as e:
print("No colored logger: {e.__class__.__name__}: {e}".format(e=e))
"grep console" is the plugin which handles this perfectly:
https://plugins.jetbrains.com/plugin/7125-grep-console
This is because the development console for PyCharm is not using the same kind of standards to display colors as your normal shell terminal (they are two very different things).
The output console for PyCharm is just a display of commands (its not a full shell with all the bells and whistles of your local terminal emulator).
You can embed a terminal into PyCharm (see the documentation on how to set it up) but doing so will not allow you to redirect the output of the built-in run commands to the terminal window. It will enable you to run arbitrary shell commands there, and avoid having to switch over to a terminal console.
Keep in mind if you have any special shell customization or fonts/glyphs these may not appear correctly in the embedded terminal, because it is using a different set of fonts and configuration.
You can try and raise this as an enhancement at the PyCharm bug tracker; if it gets enough votes it may make it in to the next release.

Launch a program at login without permissions (fedora 20)

I'm currently developing an application with QT 4.8 with a "Launch on login" option. My main problem currently is that I can't seem to find a proper way to make the program launch itself after login on Linux (Fedora 20 in my case).
My program should be able to run in the background without stopping fedora to launch.
I would also like to avoid having to ask for any sort of admin privilege since my application doesn't require any (except maybe for this option).
Finally found out about "home/.config/autostart/.desktop".
I'll have to create autostart if it's not created but from there I can chose to make or delete the file depending on what my user decided to do.
The .desktop file have to follow a particular syntax (which is not a problem for me)
[Desktop Entry]
Type=Application
Exec=</path/to/binary or command to execute>
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=<Name_to_be_displayed>
Comment=<optional comment>
In my case, I can just remove the "comment" line since just the name of the application should be enough for the user to recognize it.
You can Either keep your executable in side /etc/rc.d/rs or inside /etc/init.d folder, so that it can automatically start once device is up.
Hope this Helps.
Each user has a .bashrc file located in their home directory, you could append a command to run your application to the end of that.
That will run when only that user logs in (I think either with graphical or terminal session)
To run for all users, look at creating a systemd service if you dare, or append a line to the end of /etc/rc.local. You'll need to be root for that though.
EDIT: Don't forget to put an ampersand at the end of the command to run in background.

Webstorm run command when editor starts

Is there a way to have Webstorm run a cmd code when it stars. I'm using grunt watch and at the moment I have to go to the terminal and type "grunt watch" to start the task but I'm pretty sure I'll forget this from time to time and I want it automated.
Is there a way to have Webstorm run a cmd code when it stars.
No.
http://youtrack.jetbrains.com/issue/WEB-11818 -- star/vote/comment to get notified on progress.