Skip to content

Latest commit

 

History

History
178 lines (154 loc) · 10.2 KB

WeVoteServerCheatSheet.md

File metadata and controls

178 lines (154 loc) · 10.2 KB

A Cheat sheet, containing some commands that might help you out

Feel free to add to this!

Unable to write to the log file

PermissionError: [Errno 13] Permission denied: '/var/log/wevote'

(3.11.8) stevepodell@Steves-MBP-M1-Dec2021 log % cd /var/log (3.11.8) stevepodell@Steves-MBP-M1-Dec2021 log % ls -la Didn't find a wevote directory (3.11.8) stevepodell@Steves-MBP-M1-Dec2021 log % sudo mkdir wevote Make the directory (3.11.8) stevepodell@Steves-MBP-M1-Dec2021 log % sudo chown stevepodell:staff wevote Give it access to yourself at your (non sudo) privilege level. Be sure to substitute your Mac user name for 'stevepodell'

Stopping postgres loaded by brew, and not setup as a daemon

(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:WeVoteServer stevepodell$ pg_ctl -D /usr/local/var/postgres11.1_1 stop -s -m fast

Starting postgres loaded by brew, and not setup as a daemon

(venv3.13.2) stevepodell@Steves-MBP-M1-Dec2021 WeVoteServer %  brew services start postgresql@14
Service `postgresql@14` already started, use `brew services restart postgresql@14` to restart.
(venv3.13.2) stevepodell@Steves-MBP-M1-Dec2021 WeVoteServer % 
(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:WeVoteServer stevepodell$ "/Applications/Postgres.app/Contents/Versions/9.6/bin/psql" -p5433 -d "postgres"
or
(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:WeVoteServer stevepodell$ pg_ctl -D /usr/local/var/postgres11.1_1 -l logfile start
waiting for server to start.... done
server started
(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:WeVoteServer stevepodell$ 

in a later setup (2021)

(PycharmEnvironments) stevepodell@Steves-MacBook-Pro-32GB-Oct-2109 WeVoteServer % postgres --version
postgres (PostgreSQL) 14.0
(PycharmEnvironments) stevepodell@Steves-MacBook-Pro-32GB-Oct-2109 WeVoteServer % psql --version
psql (PostgreSQL) 14.0
(PycharmEnvironments) stevepodell@Steves-MacBook-Pro-32GB-Oct-2109 WeVoteServer % 

Setting up ngrok to send stripe webhooks to your local python server

(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:PycharmProjects stevepodell$ ~/PythonProjects/ngrok http 8000 -host-header="localhost:8000"

A very useful http inspector is made available by ngrok at http://127.0.0.1:4040/inspect/http

Then go to the Stripe console, and

launching psql and disconnecting all the postgres sessions

(PycharmEnvironments) stevepodell@Steves-MacBook-Pro-32GB-Oct-2109 WeVoteServer % psql
psql (12.3)
Type "help" for help.

stevepodell=# SELECT * from pg_database;
  oid  |    datname     | datdba | encoding | datcollate |  datctype   | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | datminmxid | dattablespace |                    datacl                    
-------+----------------+--------+----------+------------+-------------+---------------+--------------+--------------+---------------+--------------+------------+---------------+----------------------------------------------
 13690 | postgres       |     10 |        6 | C          | en_US.UTF-8 | f             | t            |           -1 |         13689 |          479 |          1 |          1663 | 
 16384 | stevepodell    |     10 |        6 | C          | en_US.UTF-8 | f             | t            |           -1 |         13689 |          479 |          1 |          1663 | 
     1 | template1      |     10 |        6 | C          | en_US.UTF-8 | t             | t            |           -1 |         13689 |          479 |          1 |          1663 | {=c/stevepodell,stevepodell=CTc/stevepodell}
 13689 | template0      |     10 |        6 | C          | en_US.UTF-8 | t             | f            |           -1 |         13689 |          479 |          1 |          1663 | {=c/stevepodell,stevepodell=CTc/stevepodell}
 94769 | WeVoteServerDB |  16385 |        6 | C          | en_US.UTF-8 | f             | t            |           -1 |         13689 |          479 |          1 |          1663 | 
(5 rows)

stevepodell=# SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'WeVoteServerDB';
 pg_terminate_backend 
----------------------
 t
 t
 t
 t
 t
 t
 t
(7 rows)

stevepodell=# 

(You may have to quit out of this session to do the next step, ^D)

Dropping the database (all data will be destroyed)

You have to terminate all the backend connections before this will work:

Then in pgAdmin 4,

  1. Select the WeVoteServerDB and right-click and drop
  2. Then in pgAdmin select Databases and right-click to recreate an empty‘WeVoteServerDB’
  3. Then in Terminal, initialize the newly created database with 'migrate'
(WeVoteServer3.6) Steves-MacBook-Pro-2017:WeVoteServer stevepodell$ python manage.py migrate

Nasty upgrade to postgres 12.2 (I did not attempt save the existing db on my local)

There has to be a better way to do this, but this is what I went through...

  165  brew install postgresql
  173  ls -la  /usr/local/Cellar/postgresql/12.2/bin/pg_ctl
  178  brew services start postgresql
  179  brew services restart postgresql
  184  lsof -i -P | grep -i "listen" | grep postgres
  189  brew services list
  190  ps aux | grep /usr/local/var/postgresl
  198  ls /usr/local/var/log/postgres.log
  199  tail /usr/local/var/log/postgres.log
  200  ls /usr/local/var/postgres
  205  cd /usr/local/var
  207  sudo mkdir postgres
  212  sudo chown stevepodell:admin postgres
  213  ls -la
  217  psql -l
  218  postgres --version
  219  initdb /usr/local/var/postgres
    (WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var % !215                          
    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
    pg_ctl: another server might be running; trying to start server anyway
    waiting for server to start.... stopped waiting
    pg_ctl: could not start server
    Examine the log output.
    (WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var % tail /usr/local/var/postgres/server.log
    2020-04-03 21:34:14.414 PDT [13229] FATAL:  lock file "postmaster.pid" already exists
    2020-04-03 21:34:14.414 PDT [13229] HINT:  Is another postmaster (PID 13133) running in data directory "/usr/local/var/postgres"?
    (WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var % !lsof
    lsof -i -P | grep post
    postgres  13133 stevepodell    5u  IPv6 0x9139afcc2c95ec77      0t0  TCP localhost:5432 (LISTEN)
    postgres  13133 stevepodell    6u  IPv4 0x9139afcc08c6d697      0t0  TCP localhost:5432 (LISTEN)
    postgres  13133 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13135 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13136 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13137 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13138 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13139 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    postgres  13140 stevepodell   10u  IPv6 0x9139afcc016b2ecf      0t0  UDP localhost:57308->localhost:57308
    (WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var % 

Adding a new "app" (directory of Python classes) to the WeVoteServer

For example to add the apple "app" at WeVoteServer/apple

  1. Make the subdirectory, and copy or create preliminary files in the directory
  2. Make sure that there is an __init__.py, it can be completely empty. In this example it would be at WeVoteServer/apple/__init__.py
  3. Assuming that the "app" has a database table, create the column layout in the models file in a class that extends "models.Model" We have dozens of Manager files and dozens of Model files that have classes that unnecessarily extend 'model.Models' and for each of these classes Django's ORM creates a useless empty table with just an id field. Consider extending 'models.Manager' or in almost all cases the class can be defined without extending anything... 'class ClassName:'
  4. Add your new app to the list in INSTALLED_APPS (within WeVoteServer/config/base.py)
  5. Generate the Migrations directory for your app, (in this example it is at WeVoteServer/apple/migrations) by typing in a terminal window ... (substitue your app name for apple!)
     python manage.py makemigrations apple
    
  6. And finally, update the local database with your new table by typing
    python manage.py migrate
    

November 2026 -- debugging with docker

https://youtrack.jetbrains.com/issue/PY-91381/Breakpoints-not-hit-with-Docker-Compose-interpreter-Accept-timed-out-and-containers-stop

Dinara Tsydenova (JetBrains)

@Steve Podell , thanks for the console output and the screenshots! The container part works. The Debugger warning: It seems that frozen modules are being used lines come from debugpy, so debugpy did start inside the container. You don't see the Starting development server line yet because of --wait-for-client: Django waits until a debugger connects, and only then starts. So that output is what we want to see at this point. You can also ignore the frozen modules warning, it doesn't affect breakpoints here.

About the missing check mark for debugpy in requirements.txt , most likely it is not related because the status bar shows Docker Compose (web) [3.6.1], and PyCharm sees Django 3.2.25. The container you started runs Python 3.12 and Django 5.2.17. So the interpreter set in PyCharm comes from a different, older image, not from this project.

As for the "Failed to launch Python DAP debug adapter" error , could you please try to change Remote address as follows:

Start the containers with docker compose -f docker-compose.yml -f docker-compose.debug.yml up --build, as you did. In the Attach to DAP dialog, change Remote address to localhost:5678. Keep the path mapping to /app. Put a breakpoint inside the index function in config/urls.py. Start the configuration with Debug. Open http://localhost:8000 in the browser. When PyCharm connects, you'll see Django's Starting development server at http://0.0.0.0:8000/ line appear in the web-1 output. When you open the page, PyCharm should stop at the breakpoint.