I am trying to develop a menu which will:
- Check to see if /tmp has write permissions from the user who is running the script.
Prompt the question : Are ALL your LOCAL repositories in the same location? e.g. /home/joe/hg/(y/n)
If YES, then, prompt for the complete PATH's, of the repos:- store the repo names (along with theor complete PATH) in a list
- copy some config files, from the directory /tmp/hg-jira-hook-config/ to ALL "home/joe/hg//.hg/"
- chmod 755 for all the config files for each repo.
If the answer to the question in Step 2 is "n" or "NO" or "no" then:
- ask for individual PATHs of the repos
- copy the config files
- chmod 755
I have a partially working script:
#!/usr/bin/env python
import sys,os
import stat
import tempfile
import shutil
__title_prefix = 'Python %i.%i.%i %s %s' % (sys.version_info[0:4] +
(sys.version_info[4] or "",))
if os.path.exists('/tmp'):
pass
else:
print '/tmp does not exist'
sys.exit()
def isgroupreadable(filepath):
st = os.stat(filepath)
return bool(st.st_mode & stat.S_IRGRP)
src = '/tmp/hg-jira-hook-config/' # This directory will be created as a result of apt-get install <package>
# and all config files will be copied
if isgroupreadable('/tmp'):
prompt_1 = ("Are ALL your LOCAL repositories in the same location? e.g. /home/joe/hg/<repo>[y/n], Press [q] when done\n")
answer_1 = raw_input(prompt_1)
if answer_1 == 'y' or None or 'YES' or 'yes':
while True:
answer_2 = raw_input("\n\nEnter the complete PATH of repos.Press [q] when done\n")
elif answer_1 == 'n' or 'NO' or 'No' or 'no':
result = raw_input("\n\nEnter the complete PATH of mercurial repositories you want this hook to be applied.Press [q] when done\n")
print result
else:
print 'cannot copy, wrong permissions on /tmp'
def main():
if __name__ == '__main__':
main()
test run:
python preinst
Are ALL your LOCAL repositories in the same location? e.g. /home/joe/hg/<repo>[y/n], Press [q] when done
y
Enter the complete PATH of repos.Press [q] when done
/home/joe/hg/app1
Enter the complete PATH of repos.Press [q] when done
/home/joe/hg/app2
Enter the complete PATH of repos.Press [q] when done
q
Enter the complete PATH of repos.Press [q] when done
so the question is:
How can i store PATH's in a LIST (or any other data structure) and How do Exit the user from this loop
listandlist.append? If so, please read a tutorial because list and append are usually covered. Exit from a loop? Are you asking aboutbreak? If so, please read a tutorial, becausebreakis usually covered.