Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:14:19+00:00 2026-05-28T20:14:19+00:00

I am trying to develop a menu which will: Check to see if /tmp

  • 0

I am trying to develop a menu which will:

  1. Check to see if /tmp has write permissions from the user who is running the script.
  2. 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:

    1. store the repo names (along with theor complete PATH) in a list
    2. copy some config files, from the directory /tmp/hg-jira-hook-config/ to ALL “home/joe/hg//.hg/”
    3. chmod 755 for all the config files for each repo.
  3. If the answer to the question in Step 2 is “n” or “NO” or “no”
    then:

    1. ask for individual PATHs of the repos
    2. copy the config files
    3. 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:14:20+00:00Added an answer on May 28, 2026 at 8:14 pm

    In all cases, the user must supply at least one path to the program. It is much much easier to supply that path or paths on the command line (using, say, argparse), than it is to make a nice interactive interface. Moreover, if you use an argument parser like argparse then your program will be automatically scriptable. In contrast, an interactive program is always as slow as its user. Therefore, I almost always prefer scriptable programs over interactive programs.

    Here is how you could do this using argparse:

    import argparse
    
    if __name__ == '__main__':
        parser=argparse.ArgumentParser()
        parser.add_argument('locations', nargs = '+')
        args=parser.parse_args()
        print(args.locations)
    

    Running

    % test.py /path/to/repo
    ['/path/to/repo']
    
    % test.py /home/joe/hg /home/joe/test
    ['/home/joe/hg', '/home/joe/test']
    

    argparse can also be used in conjunction with an interactive program. For example,

    import argparse
    import shlex
    response = raw_input('Enter repo PATHs (e.g. /path/to/repo1 /path/to/repo2)')
    parser=argparse.ArgumentParser()
    parser.add_argument('locations', nargs = '+')
    args=parser.parse_args(shlex.split(response))
    print(args.locations)
    

    argparse is part of the standard library as of Python 2.7. For Python 2.3 or better, you can install argparse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple website (ASP.NET v4), which will call Windows Search,
I am trying to develop an android application which will retrieve a voicemail message
I am trying to write a Firefox 3 add-on which will enable me to
I'm trying to configure a Bugzilla instance, which will allow my clients to login,
I'm very new to iPhone development, and I'm trying to write a function which
I am trying to get my development environment up and running, and I am
I'm trying to learn web development in Java and, from what I have seen
I'm new to WPF development with C#, and I'm trying to develop an application
I am trying to figure out which widget development platform is superior. I want
I'm starting with Android development, and I'm trying to do an application that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.