From a91d7b37ded7f5e65166856f3fab45ed764b0671 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 4 Sep 2024 19:12:27 -0400 Subject: [PATCH] latest pushes --- Package/JavaScript/README.md | 36 +++++++ Package/JavaScript/package.json | 19 ++++ Package/JavaScript/src/bellande_parser.js | 97 +++++++++++++++++++ Package/Python/README.md | 2 +- Package/Python/publish.sh | 2 + git_scripts/fix_errors.sh | 31 ++++++ git_scripts/push.sh | 25 +++++ git_scripts/repository_recal.sh | 110 ++++++++++++++++++++++ 8 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 Package/JavaScript/README.md create mode 100644 Package/JavaScript/package.json create mode 100644 Package/JavaScript/src/bellande_parser.js create mode 100755 Package/Python/publish.sh create mode 100755 git_scripts/fix_errors.sh create mode 100755 git_scripts/push.sh create mode 100755 git_scripts/repository_recal.sh diff --git a/Package/JavaScript/README.md b/Package/JavaScript/README.md new file mode 100644 index 0000000..065029a --- /dev/null +++ b/Package/JavaScript/README.md @@ -0,0 +1,36 @@ +# Bellande Format JavaScript Example + +``` +// Example usage +const bellandeFormatter = new BellandeFormat(); + +// Parse a Bellande file +const parsedData = bellandeFormatter.parseBellande('path/to/your/file.bellande'); +console.log(parsedData); + +// Write data to a Bellande file +const dataToWrite = { key: 'value', list: [1, 2, 3] }; +bellandeFormatter.writeBellande(dataToWrite, 'path/to/output/file.bellande'); +``` + +## Website NPM +- https://www.npmjs.com/package/bellande_format + +### Installation +- `npm i bellande_format` + + +``` +Name: bellande_format +Version: 0.1.0 +Summary: File type Formats +Home-page: github.com/RonaldsonBellande/bellande_format +Author: Ronaldson Bellande +Author-email: ronaldsonbellande@gmail.com +License: GNU General Public License v3.0 +Requires: numpy +Required-by: +``` + +## License +This Algorithm or Models is distributed under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/), see [LICENSE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) for more information. diff --git a/Package/JavaScript/package.json b/Package/JavaScript/package.json new file mode 100644 index 0000000..23764c0 --- /dev/null +++ b/Package/JavaScript/package.json @@ -0,0 +1,19 @@ +{ + "name": "bellande_format", + "version": "0.1.1", + "description": "File type Formats", + "main": "src/bellande_parser.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "github.com/RonaldsonBellande/bellande_format" + }, + "keywords": [ + "Bellande", + "Format" + ], + "author": "Ronaldson Bellande", + "license": "GNU General Public License v3.0" +} diff --git a/Package/JavaScript/src/bellande_parser.js b/Package/JavaScript/src/bellande_parser.js new file mode 100644 index 0000000..c86feb1 --- /dev/null +++ b/Package/JavaScript/src/bellande_parser.js @@ -0,0 +1,97 @@ +const fs = require('fs'); + +class BellandeFormat { + parseBellande(filePath) { + const content = fs.readFileSync(filePath, 'utf8'); + const lines = content.split('\n'); + return this.parseLines(lines); + } + + parseLines(lines) { + const result = {}; + const stack = [[-1, result]]; + + for (const line of lines) { + const stripped = line.trim(); + if (!stripped || stripped.startsWith('#')) continue; + + const indent = line.length - line.trimLeft().length; + while (stack.length && indent <= stack[stack.length - 1][0]) { + stack.pop(); + } + + const parent = stack[stack.length - 1][1]; + + if (stripped.includes(':')) { + const [key, value] = stripped.split(':').map(s => s.trim()); + if (value) { + parent[key] = this.parseValue(value); + } else { + const newDict = {}; + parent[key] = newDict; + stack.push([indent, newDict]); + } + } else if (stripped.startsWith('-')) { + const value = stripped.slice(1).trim(); + if (Array.isArray(parent)) { + parent.push(this.parseValue(value)); + } else { + const newList = [this.parseValue(value)]; + const lastKey = Object.keys(parent).pop(); + parent[lastKey] = newList; + stack.push([indent, newList]); + } + } + } + + return result; + } + + parseValue(value) { + if (value.toLowerCase() === 'true') return true; + if (value.toLowerCase() === 'false') return false; + if (value.toLowerCase() === 'null') return null; + if (value.startsWith('"') && value.endsWith('"')) return value.slice(1, -1); + if (/^-?\d+$/.test(value)) return parseInt(value, 10); + if (/^-?\d*\.\d+$/.test(value)) return parseFloat(value); + return value; + } + + writeBellande(data, filePath) { + const content = this.toBellandeString(data); + fs.writeFileSync(filePath, content); + } + + toBellandeString(data, indent = 0) { + if (typeof data === 'object' && data !== null) { + if (Array.isArray(data)) { + return data.map(item => `${' '.repeat(indent)}- ${this.toBellandeString(item, indent + 2)}`).join('\n'); + } else { + return Object.entries(data) + .map(([key, value]) => { + if (typeof value === 'object' && value !== null) { + return `${' '.repeat(indent)}${key}:\n${this.toBellandeString(value, indent + 2)}`; + } else { + return `${' '.repeat(indent)}${key}: ${this.formatValue(value)}`; + } + }) + .join('\n'); + } + } else { + return this.formatValue(data); + } + } + + formatValue(value) { + if (typeof value === 'string') { + return value.includes(' ') || value.includes(':') ? `"${value}"` : value; + } + if (typeof value === 'boolean') { + return value.toString(); + } + if (value === null) { + return 'null'; + } + return value.toString(); + } +} diff --git a/Package/Python/README.md b/Package/Python/README.md index ae3a3e4..c9cb265 100644 --- a/Package/Python/README.md +++ b/Package/Python/README.md @@ -1,4 +1,4 @@ -# Bellande Format Example +# Bellande Format Python Example ``` bellande_formatter = Bellande_Format() diff --git a/Package/Python/publish.sh b/Package/Python/publish.sh new file mode 100755 index 0000000..48934a9 --- /dev/null +++ b/Package/Python/publish.sh @@ -0,0 +1,2 @@ +python setup.py sdist +twine upload dist/* diff --git a/git_scripts/fix_errors.sh b/git_scripts/fix_errors.sh new file mode 100755 index 0000000..2ebdbee --- /dev/null +++ b/git_scripts/fix_errors.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Get the URL from .git/config +git_url=$(git config --get remote.origin.url) + +# Check if a URL is found +if [ -z "$git_url" ]; then + echo "No remote URL found in .git/config." + exit 1 +fi + +# Clone the repository into a temporary folder +git clone "$git_url" tmp_clone + +# Check if the clone was successful +if [ $? -eq 0 ]; then + # Remove the existing .git directory if it exists + if [ -d ".git" ]; then + rm -rf .git + fi + + # Copy the .git directory from the clone to the current repository + cp -r tmp_clone/.git . + + # Remove the clone directory + rm -rf tmp_clone + + echo "Repository cloned and .git directory copied successfully." +else + echo "Failed to clone the repository." +fi diff --git a/git_scripts/push.sh b/git_scripts/push.sh new file mode 100755 index 0000000..0b793ae --- /dev/null +++ b/git_scripts/push.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Git push what is already in the repository +git pull --no-edit; git fetch; + +# Exclude specific files and directories +EXCLUDES=(".git" ".gitignore" "executable") + +# Find all non-hidden files and directories, excluding any hidden files and directories +find . -type f ! -path '*/.*' -print0 | while IFS= read -r -d '' file; do + # Check if the file is in the exclude list + should_exclude=false + for exclude in "${EXCLUDES[@]}"; do + if [[ "$(basename "$file")" == "$exclude" ]]; then + should_exclude=true + break + fi + done + + # Add file to staging area if it's not excluded + if [ "$should_exclude" = false ]; then + git add -f "$file" + fi +done +git commit -am "latest pushes"; git push diff --git a/git_scripts/repository_recal.sh b/git_scripts/repository_recal.sh new file mode 100755 index 0000000..4c7fd4f --- /dev/null +++ b/git_scripts/repository_recal.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +# Git push what is already in the repository +git pull --no-edit; git fetch; git add .; git commit -am "latest pushes"; git push + +# Get the current directory +current_dir=$(pwd) + +# Read the remote repository URL from .git/config +remote_repo_url=$(git -C "$current_dir" config --get remote.origin.url) + +# Create a temporary directory for cloning the repository +temp_dir=$(mktemp -d) + +# Clone the repository into the temporary directory without using local references +git clone --no-local "$current_dir" "$temp_dir" + +# Switch to the temporary directory +cd "$temp_dir" + +# Create a temporary file to store the file list +tmp_file=$(mktemp) +# Create a temporary file to store the processed commits +processed_commits_file=$(mktemp) + +# Function to check if a commit has already been processed +is_commit_processed() { + local commit="$1" + + # Check if the commit is already processed + grep -Fxq "$commit" "$processed_commits_file" +} + +# Function to mark a commit as processed +mark_commit_processed() { + local commit="$1" + + # Mark the commit as processed + echo "$commit" >> "$processed_commits_file" +} + +# Function to check if a file or folder exists in the repository +file_exists_in_repo() { + local file_path="$1" + + # Check if the file or folder exists in the repository + git ls-tree --name-only -r HEAD | grep -Fxq "$file_path" +} + +# Function to process the files and folders in each commit +process_commit_files() { + local commit="$1" + + # Check if the commit has already been processed + if is_commit_processed "$commit"; then + echo "Commit $commit already processed. Skipping..." + return + fi + + # Get the list of files and folders in the commit (including subfolders) + git ls-tree --name-only -r "$commit" >> "$tmp_file" + + # Process each file or folder in the commit + while IFS= read -r line + do + # Check if the file or folder exists in the current push + if file_exists_in_repo "$line"; then + echo "Keeping: $line" + else + echo "Deleting: $line" + git filter-repo --path "$line" --invert-paths + fi + done < "$tmp_file" + + # Mark the commit as processed + mark_commit_processed "$commit" + + # Clear the temporary file + > "$tmp_file" +} + +# Iterate over each commit in the repository +git rev-list --all | while IFS= read -r commit +do + process_commit_files "$commit" +done + +# Push the filtered changes to the original repository +git remote add origin "$remote_repo_url" +git push --force origin main + +# Perform a history rewrite to remove the filtered files +git filter-repo --force + +# Fetch the changes from the remote repository +git -C "$current_dir" fetch origin + +# Merge the remote changes into the local repository +git -C "$current_dir" merge origin/main --no-edit + +# Update the local repository and reduce the size of .git if needed +git -C "$current_dir" gc --prune=now +git -C "$current_dir" reflog expire --expire=now --all +git -C "$current_dir" repack -ad + +# Clean up temporary files and directories +cd "$current_dir" +rm -rf "$temp_dir" +rm "$tmp_file" +rm "$processed_commits_file"