https://github.com/codycosta/ra-sort-5xx
Quick sorting script to automate mundane work tasks. Because why spend 20 minutes doing something when you can spend 20 hours automating it :)
https://github.com/codycosta/ra-sort-5xx
automation powershell productivity python sorting
Last synced: 2 months ago
JSON representation
Quick sorting script to automate mundane work tasks. Because why spend 20 minutes doing something when you can spend 20 hours automating it :)
- Host: GitHub
- URL: https://github.com/codycosta/ra-sort-5xx
- Owner: codycosta
- Created: 2024-10-25T18:40:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-22T19:01:38.000Z (over 1 year ago)
- Last Synced: 2025-01-30T22:23:55.406Z (over 1 year ago)
- Topics: automation, powershell, productivity, python, sorting
- Language: Python
- Homepage:
- Size: 1.86 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 5XX RA Sort Python script
```py
$$$$$$$\ $$$$$$\ $$\
$$ __$$\ $$ __$$\ $$ |
$$ | $$ |$$ / $$ | $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\
$$$$$$$ |$$$$$$$$ |$$$$$$\ $$ _____|$$ __$$\ $$ __$$\\_$$ _| $$ __$$\ $$ | $$ |
$$ __$$< $$ __$$ |\______|\$$$$$$\ $$ / $$ |$$ | \__| $$ | $$ / $$ |$$ | $$ |
$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ | $$ |$$\ $$ | $$ |$$ | $$ |
$$ | $$ |$$ | $$ | $$$$$$$ |\$$$$$$ |$$ | \$$$$ |$$\ $$$$$$$ |\$$$$$$$ |
\__| \__|\__| \__| \_______/ \______/ \__| \____/ \__|$$ ____/ \____$$ |
$$ | $$\ $$ |
$$ | \$$$$$$ |
\__| \______/
```
# Quick Section Links
### [Script Usage](#usage)
### [PowerShell Shortcuts](#creating-a-profile-function-shortcut)
### [Download Options](#how-to-download-ra-sortpy)
### [Setting up Python](#getting-started-with-python)
>[!IMPORTANT]
>Please read if you are new to using python, new to terminal scripting, or need assistance with setting up your machine.
>[!NOTE]
>RA-sort.py will automatically create a backup folder to dump a copy of all RA files into before sorting. This way if something were to go wrong during execution, or you as the user are unhappy with the results, there is a safe restore point to reset the folder to how it started.
### Turn a cluttered directory into a well organized file storage, ready for excel!
#### Setup should not take more than 20 minutes and is a one time deal, after that there's no other prerequisites to begin use. I've tried to make this guide as easy and beginner friendly as possible.
# Usage
## Step 0: Launch a Terminal
#### Any terminal you have installed will work (cmd, bash, powershell, etc...)
The default windows terminal on our KLA machines is Windows Command Prompt. To launch this just press the windows key and type 'cmd':\

To elevate your terminal game, I'd recommend using Powershell rather then Command Prompt, which can be easily found in the same fashion by searching for Powershell at the windows start menu:\

## Step 1: Navigate to RA folder
For example let's say we have some RA's that exist in the following folder:
```powershell
~/Documents/5XX/SV_RA/
```
## Step 2: Run RA-sort.py
Let's say we downloaded and moved RA-sort.py to the following folder. Continue to the next section for download instructions.
```powershell
~/Documents/5XX/RA-sort.py
```
>[!TIP]
>After downloading RA-sort.py from github here, I'd recommend keeping it (or a copy) close to, or even inside, the RA directory you intend to sort. This way, typing out the file path is not a hassle.
Your command line execution would look something like this:
```powershell
~/Documents/5XX/SV_RA/ > [python | py] [path to RA-sort.py]
or with the example file/folder names:
~/Documents/5XX/SV_RA/ > python ../RA-sort.py
```
>[!TIP]
>You can use either **python** or **py** prefixes to reference the python file.
## Optional Step 3: Organize Excel files along with RA files
You can also elect to have the script copy and organize your excel workbooks along with the RA files.\
To do this, after calling RA-sort.py, add an extra argument that references the path to the blank workbook folder.\
Say we have our blank workbooks in the following folder:
```powershell
~/Documents/5XX/blank-workbooks/
```
To reference this folder we would run the following:
```powershell
~/Documents/5XX/SV_RA/ > [python | py] [path to RA-sort.py] [path to blank workbooks]
or with the example file/folder names:
~/Documents/5XX/SV_RA/ > python ../RA-sort.py ../blank-workbooks
```
>[!WARNING]
>If you would like to do this, make sure that each of your blank excel workbooks at least has 'COG', 'EPSM', 'CETUS' and 'SL' in the name.
>[!TIP]
> Like with the RA-sort.py script, I recommend keeping your folder of blank excel workbooks nearby to easily access
When organizing the excel workbooks, RA-sort.py will count the number of RA P0 files in each folder and will duplicate the needed excel workbook should the quantity of unique RA files exceed 10. This way there are the required number of excel files within each base/threshold folder.
## Example
During testing, I stored some mock RA files in the following folder:
```powershell
~/KLA-RA-scripts/sample-RAs/
```
My copy of RA-sort.py was stored in the previous folder:
```powershell
~/KLA-RA-scripts/RA-sort.py
```
And my blank excel workbooks in the following folder:
```powershell
~/KLA-RA-scripts/blank-workbooks/
```
### Executing RA-sort.py on my end would look like this:
```powershell
~/KLA-RA-scripts/sample-RAs/ > py ../RA-sort.py ../blank-workbooks
```
easy peasy :)
# Creating A Profile Function Shortcut
## Recommended for easy repeated use
If rerunning this script using the above command line arguments gets boring and repetitive, here's a shortcut to help you speed things up by assigning a powershell function to serve as an alias for the command:
## Step 0: Launch a Terminal
You know how to do this already...(launch PowerShell)
## Step 1: Set Your Windows Execution Policy
to do this just run the following in any folder in the terminal:
```powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
```
## Step 2: Create A Powershell Function
This is easy to do. Open your $profile script by running the following in any folder:
```powershell
notepad $profile
```
this should launch the profile script in none other than the windows notepad app
Here's the basic template. Type this out in your notepad $profile window.
```powershell
function [some function name] {
[python | py] [your path to RA-sort.py] [your path to blank excel workbooks]
}
```
#### Be sure to include the entire file and folder path for both RA-sort.py and the blank workbook folders. Using the above example files/folders here's what my function would look like:
```powershell
function pysort {
py 'C:\Users\Cody\KLA_RA_scripts\RA-sort.py' 'C:\Users\Cody\KLA_RA_scripts\blank-workbooks'
}
```
>[!IMPORTANT]
> - Remember to update this script if you download a new version release of RA-sort or move your files to different locations
> - Notice how my file and folder paths are wrapped in **quotes** ('' or "", doesn't matter).\
> -- This is necessary when your file or folder names have spaces (' ') in them, but is good practice to do anyway just in case.
> - Do not end folder names with a slash '\\' or '/'. Listing it as ~/blank-workbooks/ will crash RA-sort.py as the OS cannot interpret the folder name and you'll receive a partial completion
Great! Now we have a function to call RA-sort.py without having to pass any command arguments to the terminal when running. The next time you go to run the script on a data set, all you'll need to do is call the function name:
```powershell
~/KLA-RA-scripts/sample-RAs/ > pysort
```
You can go ahead and save and close your notepad file now!
You'll need to relaunch the terminal for changes to take effect.
>[!WARNING]
> I would recommend testing the script first and seeing some success before assigning an alias function.\
> This ensures your spelling is correct and you have verified the files and folders arguments passed to the function are acceptable.
You'll need to relaunch the terminal for changes to take effect
### And that's all, your terminal should be ready for shortcutting
# How To Download RA-sort.py
## Stable Releases (Recommended)
>[!IMPORTANT]
>To get the latest and greatest version of the file I would recommend downloading the zip file from the Releases tab near the top of the page
## Step 1. Click on releases (or the version with the attached 'Latest' tag)

## Step 2. Click on either **Source code** button to download your preferred file format, both are essentially zip files

### This will drop a zip file of all of the repository's contents into your downloads folder. From here you can pick out RA-sort.py

## Experimental Pre-releases
>[!WARNING]
>RA-sort.py may not perform as intended with pre-release versions
## Step 1. At the top of the page if you are reading this, click on RA-sort.py

## Step 2. Next, on the top right of the file page, click the button to download raw file

### That's it, your file will be in your downloads folder
# Getting Started With Python
## Step 1: Make sure you have python installed (version 3.7 or later)
Python can be downloaded from https://www.python.org/. I would recommend installing the latest version if you are unsure.\
To check if your machine already has a version of python installed, simply press the windows key and search for 'python':\

If you do not see a version installed, follow the instructions on Python's website linked above for a fresh install. After downloading, be sure to run the .exe file to install it.
>[!NOTE]
> During installation, the program will ask you if you would like to add Python to the system path, check this box if you see it to avoid needing to do Step 2.\
> Step 3 is recommended to do anyway
## Step 2: Verify Python is on Your System Path
This step will take the most work, but is not difficult to do
An easy way to check if python's executable file is found on your path is to run the following in any folder in the terminal:
```powershell
> gcm python
output:
CommandType Name Version Source
----------- ---- ------- ------
Application python.exe 3.12.31... C:\Users\Cody Costa\AppData\Local\Programs\Python\Python312\python.exe
```
If you don't see a valid result with a source similar to the following then proceed with the rest of the guide:
```powershell
C:\Users\\AppData\Local\Programs\Python\Python<3XX>\
```
Press the windows key and type out 'env', and click on **Edit the system environment variables**

A new 'System Properties' window will open, and we want to click on **Environment Variables**\

This will bring up a new window called 'Environment Variables'\
Navigate to the **system variables** section and click on the item labeled Path and then click **Edit**

Another new window will pop up, and we will then click on **New**\
In the field that pops up, here is where you will paste in your PYTHON PATH from earlier\
You can see mine listed at the bottom\

#### Go ahead and click on **OK** on all the open windows to close them, and you are done with path setup!
## Step 3: Diasabling Execution Aliasing
This part is easier than step 2.\
Press the windows key and search for 'app exec', and click on **Manage app execution aliases**

Scroll down until you see 2 programs named **App Installer** with python.exe and python3.exe listed below the titles.\
Turn both of these **OFF**\

### Setup is finished, your computer is ready to run Python
### Navigate back to the top to read about the file Usage