(20241122) Project created.
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
/.venv/
|
||||||
|
/.idea/
|
||||||
|
**/__pycache__/
|
||||||
|
__pycache__/
|
||||||
|
|
||||||
|
*.pem
|
||||||
|
*.pyc
|
||||||
|
*.pyd
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
|
||||||
|
# GIT CHEATSHEET
|
||||||
|
## By Sharvil (20240927)
|
||||||
|
Perform these steps on creating a new project.
|
||||||
|
|
||||||
|
_**ASSUMPTION:** You are already in your project directory in the command line terminal._
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### STEP 0.
|
||||||
|
#### Initialize Git in your new project:
|
||||||
|
Do this when creating a new project directory.
|
||||||
|
Do this **ONLY ONCE**.
|
||||||
|
```commandline
|
||||||
|
git init
|
||||||
|
```
|
||||||
|
|
||||||
|
### STEP 1.
|
||||||
|
#### Create a `.gitignore` file:
|
||||||
|
Add files/directories in it which you don't want to sync to git.
|
||||||
|
Update this as frequently as your project needs you to. Start with this:
|
||||||
|
```
|
||||||
|
/.venv/
|
||||||
|
/.idea/
|
||||||
|
**/__pycache__/
|
||||||
|
*.pem
|
||||||
|
```
|
||||||
|
|
||||||
|
### STEP 2.
|
||||||
|
#### Create a repository on Gitea (web UI):
|
||||||
|
Do this **ONLY ONCE**.
|
||||||
|
Open the following URL: https://wtt.ditscentre.in/ and sign in.
|
||||||
|
- Ensure that the owner is `ditscentre` (img 0).
|
||||||
|
- Give your repository a name. Preferably keep it the same as the project name that you made locally (img 0).
|
||||||
|
- Type in a brief description of your project (img 0).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Ensure that the default branch is `master` (img 1).
|
||||||
|
- Create the repository (img 1).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### STEP 3.
|
||||||
|
#### Add files and directories to the staging area:
|
||||||
|
The following command adds everything to the staging area.
|
||||||
|
The '.' is important, it refers to the current directory.
|
||||||
|
```commandline
|
||||||
|
git add .
|
||||||
|
```
|
||||||
|
|
||||||
|
### STEP 4.
|
||||||
|
#### Commit the changes to local git:
|
||||||
|
This step commits all the added (staged) changes to the local git instance with the provided comment.
|
||||||
|
```commandline
|
||||||
|
git commit -m "you comment here..."
|
||||||
|
```
|
||||||
|
|
||||||
|
### STEP 5.
|
||||||
|
#### We push the local commits to the repository:
|
||||||
|
The format of the command is:
|
||||||
|
```
|
||||||
|
git push -u <repo_url> <branch_name>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## For Python Devs: How to add a common subtree (like `utils_v2`)
|
||||||
|
|
||||||
|
The format of the command is:
|
||||||
|
```
|
||||||
|
git subtree add --prefix=<local_dir> <subtree_repo_url> <branch_name> --squash
|
||||||
|
```
|
||||||
|
Before you start: ensure that you have committed all pending changes. Then run the following command **ONLY ONCE**:
|
||||||
|
```commandline
|
||||||
|
git subtree add --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash
|
||||||
|
```
|
||||||
|
This will create a new directory named `utils_v2` in your project.
|
||||||
|
**Do NOT change the files in it.** Just import and use them in your scripts.
|
||||||
|
When you need to get the latest updates to these files, you must run a modification of the previous command:
|
||||||
|
```commandline
|
||||||
|
git subtree pull --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash
|
||||||
|
```
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Just found this better than remembering the freeze command.
|
||||||
|
# This is beyond silly.
|
||||||
|
# Okay, bye!
|
||||||
|
pip3 freeze > requirements.txt
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Run this on the server.
|
||||||
|
# Not suitable for collaborative environments:
|
||||||
|
echo "Pulling from git."
|
||||||
|
git pull https://wtt.ditscentre.in/ditscentre/api_utils_converse_v2.git
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Kill all the scripts:
|
||||||
|
echo "Killing the script."
|
||||||
|
pkill -9 -f "$(pwd)/api/main.py"
|
||||||
|
|
||||||
|
# Get the name of the current directory,
|
||||||
|
# and kill the monitors of the above scripts:
|
||||||
|
echo "Killing the monitors."
|
||||||
|
PARENT_WD=$(pwd)
|
||||||
|
CURRENT_DIR_NAME=$(basename "$PARENT_WD")
|
||||||
|
pgrep -f "$CURRENT_DIR_NAME.*python" | xargs kill -9
|
||||||
|
|
||||||
|
# All done:
|
||||||
|
echo "Done!"
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# To pull any updates made to utils from another project:
|
||||||
|
echo "Pulling from git."
|
||||||
|
git subtree pull --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Move to the directory of the subtree:
|
||||||
|
echo "Changing directory."
|
||||||
|
cd "utils_v2" || { echo "Failed to change directory."; exit 1; }
|
||||||
|
|
||||||
|
# Accept a comment from the terminal:
|
||||||
|
echo "Comment: "
|
||||||
|
read -r COMMENT
|
||||||
|
|
||||||
|
# Add all the modified files to the intended commit:
|
||||||
|
git add .
|
||||||
|
echo "Files added."
|
||||||
|
|
||||||
|
# Make the commit:
|
||||||
|
git commit -m "$COMMENT"
|
||||||
|
echo "Commit done."
|
||||||
|
|
||||||
|
# Return to the parent directory:
|
||||||
|
echo "Returning to parent directory."
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo "Pushing to git."
|
||||||
|
git subtree push --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# When you need to re-pull the whole utils subtree because of merge conflicts:
|
||||||
|
echo "Removing existing utils subtree."
|
||||||
|
git rm -r "utils_v2"
|
||||||
|
echo "Removing existing utils directory."
|
||||||
|
rm -r "utils_v2"
|
||||||
|
git add .
|
||||||
|
git commit -m "Resetting utils subtree."
|
||||||
|
echo "Adding utils subtree from git."
|
||||||
|
git subtree add --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# A quick command to copy sensitive files from development machine to server without involvement of GitHub:
|
||||||
|
|
||||||
|
# Read the servers from the file into an array:
|
||||||
|
mapfile -t SERVERS < servers.txt
|
||||||
|
|
||||||
|
# Display the numbered list of server options:
|
||||||
|
echo "Please select a server:"
|
||||||
|
for i in "${!SERVERS[@]}"; do
|
||||||
|
echo "$((i + 1)). ${SERVERS[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Prompt the user for their selection
|
||||||
|
read -rp "Select a server by the number ... : " SELECTION
|
||||||
|
|
||||||
|
# Get a port no.:
|
||||||
|
read -rp "Set a port no. .................. : " PORT
|
||||||
|
|
||||||
|
# Validate the selection
|
||||||
|
if [[ $SELECTION -gt 0 && $SELECTION -le ${#SERVERS[@]} ]]; then
|
||||||
|
|
||||||
|
# Note down the selection in a variable:
|
||||||
|
SELECTED_SERVER=${SERVERS[$((SELECTION - 1))]}
|
||||||
|
|
||||||
|
# Ask the user which directory he wants to upload and his username on the server:
|
||||||
|
read -rp "Your username on the server ..... : " USER
|
||||||
|
read -rp "Directory to send ............... : " SOURCE
|
||||||
|
|
||||||
|
# Run the rsync command:
|
||||||
|
PROJECT_DIRECTORY=$(basename "$PWD")
|
||||||
|
DESTINATION="$USER@$SELECTED_SERVER://home/$USER/programming/python/$PROJECT_DIRECTORY"
|
||||||
|
echo "Trying to send '$SOURCE' to '$DESTINATION'"
|
||||||
|
rsync -avz --mkpath --progress -e "ssh -p $PORT" "$SOURCE" "$DESTINATION"
|
||||||
|
|
||||||
|
# Exit with success (assuming that the actual data sending went well):
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# In case of a wrong server selection, exit with failure.
|
||||||
|
echo "Invalid selection. Please run the script again."
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
fi
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Use this to run the microservice without any docker setup.
|
||||||
|
source .venv/bin/activate
|
||||||
|
python3 "$(pwd)/api/main.py" --host "127.0.0.1" --port 5205 --workers 4 --script-id "kps_tcaoff_mUPO2QB8" &
|
||||||
|
deactivate
|
||||||
|
|
||||||
|
# All done:
|
||||||
|
echo "Done!"
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
kbdev.bicree.com
|
||||||
|
wtt.ditscentre.in
|
||||||
|
del.ditscentre.in
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# We create a Virtual Environment.
|
||||||
|
# The format is:
|
||||||
|
# python<version> -m venv <virtual_env_name>
|
||||||
|
echo "Making a virtual environment (if needed)."
|
||||||
|
python3 -m venv .venv
|
||||||
|
|
||||||
|
# Next we activate the newly created Virtual Environment.
|
||||||
|
echo "Activating the virtual environment."
|
||||||
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
# Now we install the requirements.
|
||||||
|
echo "Installing pending requirements."
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
# Now we deactivate the Virtual Environment.
|
||||||
|
echo "Deactivation the virtual environment."
|
||||||
|
deactivate
|
||||||
|
|
||||||
|
# Setup Done.
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# A quick command to connect to any of the available servers.
|
||||||
|
|
||||||
|
# Read the servers from the file into an array:
|
||||||
|
mapfile -t SERVERS < servers.txt
|
||||||
|
|
||||||
|
# Display the numbered list of server options:
|
||||||
|
echo "Please select a server:"
|
||||||
|
for i in "${!SERVERS[@]}"; do
|
||||||
|
echo "$((i + 1)). ${SERVERS[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Prompt the user for their selection
|
||||||
|
read -rp "Select a server by the number ... : " SELECTION
|
||||||
|
|
||||||
|
# Validate the selection
|
||||||
|
if [[ $SELECTION -gt 0 && $SELECTION -le ${#SERVERS[@]} ]]; then
|
||||||
|
|
||||||
|
# Note down the selection in a variable:
|
||||||
|
SELECTED_SERVER=${SERVERS[$((SELECTION - 1))]}
|
||||||
|
|
||||||
|
# Ask the user which directory he wants to upload and his username on the server:
|
||||||
|
read -rp "Your username on the server ..... : " USER
|
||||||
|
|
||||||
|
# Run the command:
|
||||||
|
ssh -p 19991 "$USER@$SELECTED_SERVER"
|
||||||
|
|
||||||
|
# Exit with success (assuming that the actual data sending went well):
|
||||||
|
echo "session ended"
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# In case of a wrong server selection, exit with failure.
|
||||||
|
echo "Invalid selection. Please run the script again."
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
fi
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# NOTES:
|
||||||
|
# Run this on the development machine.
|
||||||
|
# NOT to be used in a collaborative environment:
|
||||||
|
|
||||||
|
# Accept a comment from the terminal:
|
||||||
|
echo "Comment: "
|
||||||
|
read -r COMMENT
|
||||||
|
|
||||||
|
# Add all the modified files to the intended commit:
|
||||||
|
git add .
|
||||||
|
echo "Files added."
|
||||||
|
|
||||||
|
# Make the commit:
|
||||||
|
git commit -m "$COMMENT"
|
||||||
|
echo "Commit done."
|
||||||
|
|
||||||
|
# Push th commit to git:
|
||||||
|
git push -u https://wtt.ditscentre.in/ditscentre/api_utils_converse_v2.git master
|
||||||
|
echo "Attempt done. Exiting."
|
||||||
Reference in New Issue
Block a user