Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Linux, and mock files Write a python script to automatically submit assign

ID: 3713705 • Letter: U

Question

Using Linux, and mock files

Write a python script to automatically submit assignments through git (with our course structure) Your script should Take in arguments from the command line o First argument is the branch name/assignment name o The next n arguments are the files to be submitted Your commit message should say what files you added o "Added E02.txt" o "Added L04.txt task2.c task3.c" s ./git_submit.py E02 E02.txt Switching to master branch... Pulling the latest from master. Succesfully branched to E02. Adding the file submissions/E02/E02.txt Committing... Pushing..- Success! s ./git_submit.py 104 L04.txt task2.c task3.c Switching to master branch... Pulling the latest from master. Succesfully branched to L04 Adding the file submissions/E02/E02.txt Committing... Pushing..- Success!

Explanation / Answer

NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.

My workspace has some issues. So not able to check the entire workflow. But script handles correctly in case of any issues. So please check and let me know if there are any problems, i will help.

Unix Terminal> cat git_submit.py

#!/usr/local/bin/python3

import sys

import os

def main():

# validating the command line arguments passed

if len(sys.argv) < 3:

print ('Must pass atleast 2 arguments')

print ('Usage:', sys.argv[0], '<branch name> <file1> <file2> ....')

sys.exit(1)

# capturing branch name from the command line

branch_name = sys.argv[1]

# switching to master branch

print('Switching to master branch...')

cmd = 'git checkout -b master'

res = os.system(cmd)

if res:

print('Not able to switch to master. please check if you are in git directory')

sys.exit(1)

# pulling the latest changes from master

cmd = 'git pull'

print('Pulling the latest changes from master.')

res = os.system(cmd)

if res:

print('Not able to pull latest changes. Please check')

sys.exit(1)

# checkout to the given branch

cmd = 'git checkout -b ' + branch_name

res = os.system(cmd)

if res:

print('Not able to checkout to the given branch', branch_name)

sys.exit(1)

# successfully branched to given branch

print('Successfully branched to', branch_name)

# iterating through each file given in command line and adding to the provided branch

for file_name in sys.argv[2:]:

print('Adding the file', branch_name + '/' + file_name)

cmd = 'git add ' + file_name

res = os.system(cmd)

if res:

print('Not able to add the file', file_name, 'to the branch', branch_name, 'please check...')

sys.exit(1)

# committing the changes

print('Committing...')

cmd = 'git commit -m "Adding new files to branch"'

res = os.system(cmd)

if res:

print('Not able to commit the changes, please check.')

sys.exit(1)

# pushing the changes

print('Pushing...')

cmd = 'git push'

res = os.system(cmd)

if res:

print('Not able to push the changes, please check.')

sys.exit(1)

print('Success!')

if __name__=='__main__':

main()

Unix Terminal>

Code link: pasted.co/8fa8fe76

Code output snapshot:

Unix Terminal> python3 git_submit.py TEST a b

Switching to master branch...

Switched to a new branch 'master'

Pulling the latest changes from master.

fatal: No remote repository specified. Please, specify either a URL or a

remote name from which new revisions should be fetched.

Not able to pull latest changes. Please check

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote