Team Ai
Apppublic

Oranblock/Shell_fixer

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py55 linesDownload Raw Back to root
1import streamlit as st2import os3from subprocess import Popen, PIPE4import re5 6# Function to upload and save files7def save_uploadedfile(uploadedfile):8    with open(os.path.join("uploads", uploadedfile.name), "wb") as f:9        f.write(uploadedfile.getbuffer())10    return uploadedfile.name11 12# Function to analyze shell script with shellcheck13def analyze_shell_script(script_path):14    command = f'shellcheck {script_path}'15    process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)16    stdout, stderr = process.communicate()17    return stdout.decode(), stderr.decode()18 19# Function to fix common shell script issues (simple example)20def fix_shell_script_errors(script_content):21    # Example: Remove unused variables warning (SC2034)22    fixed_content = re.sub(r'\b\w+=["\'].+["\']\s*# SC2034', '', script_content)23    return fixed_content24 25# Streamlit app layout26st.title("Shell Script Investigation and Fixing App")27 28# Upload the file29uploaded_file = st.file_uploader("Upload your shell script", type=["sh"])30 31if uploaded_file is not None:32    # Save uploaded file33    file_name = save_uploadedfile(uploaded_file)34    st.write(f"File '{file_name}' uploaded successfully!")35 36    # Show the content of the uploaded file37    st.subheader("Uploaded Shell Script")38    script_content = uploaded_file.read().decode("utf-8")39    st.code(script_content, language='bash')40 41    # Provide button to run investigation42    if st.button("Investigate"):43        stdout, stderr = analyze_shell_script(os.path.join("uploads", file_name))44        if stderr:45            st.error(f"Error during analysis: {stderr}")46        else:47            st.subheader("Investigation Results")48            st.text(stdout)49 50    # Provide button to fix errors51    if st.button("Fix Issues"):52        fixed_content = fix_shell_script_errors(script_content)53        st.subheader("Fixed Shell Script")54        st.code(fixed_content, language='bash')55        st.download_button("Download Fixed Script", data=fixed_content, file_name=f"fixed_{file_name}")