Storing jam.py Application in GitLab

126 views
Skip to first unread message

Ali

unread,
Apr 28, 2022, 10:04:00 AM4/28/22
to Jam.py Users Mailing List
Hi

So I posted a message a while back about managing version controlling/source code changes between two instances of jam.py.  Below is the Python script I've written which has been working for me.

The entire process is completely upside down, I develop the application in a Development instance of my jam.py application, run the Python script to create 'source code' (this is incremental) and then commit this to my GitLab repo which handles only committing what's changed.  

I can then use the GitLab UI to show me the diffs between production and development.  It means I have point in time backups of the application so if I wreck something then I can go back to it.  Mostly this is to give me visibility of which bits of the application I "touched" when I made changes because often this is multiple items, plus database changes representing permissions, form layouts, indexes etc.

The Python script is relatively straight-forward, you pass the location of the installed jam.py application, the folder where you want to create your source repository, and a message for Git to commit the changes like this:

/bin/python3 /home/applications/codestash/codestash.py -j ../training-dev -o ../training-dev-src -m "Initial work on competency management"

It does the following:
  1. creates a copy of the CSS and index.html files
  2. creates a copy of the admin.sqlite database with a date/time stamp (these aren't committed to the repo)
  3. Runs sqldiff for each of the tables in the current jam.py admin.sqlite compared to the one from the time before (defined at the top of the script) and outputs individual SQL files for each table showing what's changed so these can be shown in GitLab
  4. Gets the categories (catalogs, journals, details etc.) from the jam.py sqlite
  5. Pulls the JSON, JS and Python code for each item out of the database into files named after the item and in folders based on the category
  6. Commits it to GitLab
Some screenshots which hopefully explain a bit better...

**diffs** is the SQL diffs from the tables in admin.sqlite which have changed - here I added some indices to some tables so the sqldiff process shows what changed

SQLDiffs.png

GitLab

Screenshot 2022-04-28 at 14.38.28.png

**Source code**

Here is the output from generating a "src" tree

Screenshot 2022-04-28 at 14.45.03.png

In GitLab:

Screenshot 2022-04-28 at 14.57.13.png

If anyone wants to ask any questions etc. then feel free.  The script is attached but provided as-is, no warranty express or implied, under the MIT License.

codestash.py

Danijel Kaurin

unread,
Apr 28, 2022, 1:42:09 PM4/28/22
to Jam.py Users Mailing List
Thanks Ali.

Great work for both posts.

Andrew Yushev

unread,
Apr 29, 2022, 4:18:47 AM4/29/22
to Danijel Kaurin, Jam.py Users Mailing List
I totally agree with Danijel.

чт, 28 апр. 2022 г. в 20:42, Danijel Kaurin <yonika...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/e86024e9-a938-4b0a-9602-a7840e08aa06n%40googlegroups.com.

Drazen D. Babic

unread,
May 1, 2022, 10:35:35 AM5/1/22
to Jam.py Users Mailing List
HI Ali, 

cheers for the script! Tried it but no go. Is the dependency gitpython or python-git?
So in demo folder I do this:
~/Downloads/jam.py-5.4.118/demo $ python ../../codestash.py -j ../demo/ -o ../../codestash_demo_git -m "Initial"
Traceback (most recent call last):
  File "../../codestash.py", line 80, in copy_database
    fp = shutil.copy2(db, output_path)
  File "/usr/local/lib/python3.8/shutil.py", line 432, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/local/lib/python3.8/shutil.py", line 261, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/home/dbabic/Downloads/codestash_demo_git/databases/admin-1651415189.sqlite'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../../codestash.py", line 190, in <module>
    db_copy = copy_database(db, output_path)
  File "../../codestash.py", line 83, in copy_database
    print(f'The database copy process failed with {e.message}')
AttributeError: 'FileNotFoundError' object has no attribute 'message'


Thoughts?

Only index.html and css/project.css folder was created.

Ta

Ali

unread,
May 6, 2022, 6:52:52 AM5/6/22
to Jam.py Users Mailing List
Hey

Apologies, I've been a bit snowed under.  There were some issues around creating default directories etc. when running for the first time so I've added some error checking code and creation of missing directories stuff too.  Also, the script will check to make sure the output folder is already initialised as a Git repo if you're using the automatic commit option (which is now optional so you can generate the source code tree without committing)

Please find the latest version attached.

Cheers,
Ali

codestash.py

Drazen D. Babic

unread,
May 6, 2022, 8:11:44 AM5/6/22
to Jam.py Users Mailing List
This is fantastic! I see the potential even with no git, like naming all with timestamp and doing a diff! 

Thanks!

Regards
D.

Maxwell Morais

unread,
May 6, 2022, 8:30:40 AM5/6/22
to Drazen D. Babic, Jam.py Users Mailing List
I loved that!

This will for sure help in resolving a problem of having more than 1 dev working around the same project!

May can help also to define apps as module, so we can develop small apps (as modules) and combine they in a single big app!


For sure I'll take a deep look on this project possibilities!

Loved! 

--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages