예제 #1
0
def edit_repo(cname, repo_name, do_quick_delete):
    if do_quick_delete:
        delete_repo(cname, repo_name, do_quick_delete)
    else:
        action = prompt_user('What would you like to do?', [
            'Delete the repository',
            'Edit the description',
            'Mark repository as non-publishing',
            'Mark repository as publishing',
            'Enable obsolescence support (experimental)',
            'Disable obsolescence support',
            ])
        if action == 'Edit the description':
            edit_repo_description(repo_name)
        elif action == 'Delete the repository':
            delete_repo(cname, repo_name, False)
        elif action == 'Mark repository as non-publishing':
            set_repo_publishing(repo_name, False)
        elif action == 'Mark repository as publishing':
            set_repo_publishing(repo_name, True)
        elif action == 'Enable obsolescence support (experimental)':
            set_repo_obsolescence(repo_name, True)
        elif action == 'Disable obsolescence support':
            set_repo_obsolescence(repo_name, False)
    return
예제 #2
0
def edit_repo_description(repo_name):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    print(EDIT_DESCRIPTION.format(user_dir=user_repo_dir, repo=repo_name))
    selection = prompt_user('Proceed?', ['yes', 'no'])
    if selection != 'yes':
        return

    repo_path = get_and_validate_user_repo(repo_name)
    repo_description = raw_input('Enter a one line descripton for the '
                                 'repository: ')
    if repo_description == '':
        return

    repo_description = escape(repo_description)

    config_path, config = get_user_repo_config(repo_path)

    if not config.has_section('web'):
        config.add_section('web')

    config.set('web', 'description', repo_description)

    with open(config_path, 'w+') as fh:
        config.write(fh)

    run_command('%s -R %s replicatehgrc' % (HG, repo_path))
def edit_repo(cname, repo_name, do_quick_delete):
    if do_quick_delete:
        delete_repo(cname, repo_name, do_quick_delete)
    else:
        action = prompt_user('What would you like to do?', [
            'Delete the repository',
            'Edit the description',
            'Mark repository as non-publishing',
            'Mark repository as publishing',
            'Enable obsolescence support (experimental)',
            'Disable obsolescence support',
            ])
        if action == 'Edit the description':
            edit_repo_description(repo_name)
        elif action == 'Delete the repository':
            delete_repo(cname, repo_name, False)
        elif action == 'Mark repository as non-publishing':
            set_repo_publishing(repo_name, False)
        elif action == 'Mark repository as publishing':
            set_repo_publishing(repo_name, True)
        elif action == 'Enable obsolescence support (experimental)':
            set_repo_obsolescence(repo_name, True)
        elif action == 'Disable obsolescence support':
            set_repo_obsolescence(repo_name, False)
    return
def edit_repo_description(repo_name):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    print(EDIT_DESCRIPTION.format(user_dir=user_repo_dir, repo=repo_name))
    selection = prompt_user('Proceed?', ['yes', 'no'])
    if selection != 'yes':
        return

    repo_path = get_and_validate_user_repo(repo_name)
    repo_description = raw_input('Enter a one line descripton for the '
                                 'repository: ')
    if repo_description == '':
        return

    repo_description = escape(repo_description)

    config_path, config = get_user_repo_config(repo_path)

    if not config.has_section('web'):
        config.add_section('web')

    config.set('web', 'description', repo_description)

    with open(config_path, 'w+') as fh:
        config.write(fh)

    run_command('%s -R %s replicatehgrc' % (HG, repo_path))
예제 #5
0
def edit_repo_description (cname, repo_name):
    global doc_root
    user = os.getenv ('USER')
    user_repo_dir = user.replace ('@', '_')
    print 'You are about to edit the description for hg.mozilla.org/users/%s/%s.' % (user_repo_dir, repo_name)
    print 'If you need to edit the description for a top level repo, please quit now and file an IT bug for it.'
    selection = prompt_user ('Proceed?', ['yes', 'no'])
    if (selection == 'yes'):
	if os.path.exists ('%s/users/%s/%s' % (doc_root[cname], user_repo_dir, repo_name)):
            repo_description =  raw_input ('Enter a one line descripton for the repository: ')
            if (repo_description != ''):
		repo_description = escape (repo_description)
                repo_config = ConfigParser.RawConfigParser ()
                repo_config_file = '%s/users/%s/%s' % (doc_root[cname], user_repo_dir, repo_name) + '/.hg/hgrc'
                if not os.path.isfile (repo_config_file):
                    run_command ('touch ' + repo_config_file)
                    run_command ('chown ' + user + ':scm_level_1 ' + repo_config_file)
                if repo_config.read (repo_config_file):
                    repo_config_file = open (repo_config_file, 'w+')
                else:
                    sys.stderr.write ('Could not read the hgrc file for /users/%s/%s.\n' % (user_repo_dir, repo_name))
                    sys.stderr.write ('Please file an IT bug to troubleshoot this.')
                    sys.exit (1)
                if not repo_config.has_section ('web'):
                    repo_config.add_section ('web')
                repo_config.set ('web', 'description', repo_description)
                repo_config.write (repo_config_file)
                repo_config_file.close ()
        else:
            sys.stderr.write ('Could not find the repository at /users/%s/%s.\n' % (user_repo_dir, repo_name))
            sys.exit (1)
예제 #6
0
def edit_repo (cname, repo_name, do_quick_delete):
    if do_quick_delete:
        delete_repo (cname, repo_name, do_quick_delete)
    else:
      action = prompt_user ('What would you like to do?', ['Delete the repository', 'Edit the description'])
      if action == 'Edit the description':
        edit_repo_description (cname, repo_name)
      elif action == 'Delete the repository':
        delete_repo (cname, repo_name, False) 
    return
예제 #7
0
def delete_repo(cname, repo_name, do_quick_delete):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    if os.path.exists('%s/users/%s/%s' % (DOC_ROOT, user_repo_dir, repo_name)):
        if do_quick_delete:
            do_delete(user_repo_dir, repo_name)
        else:
            print '\nAre you sure you want to delete /users/%s/%s?' % (user_repo_dir, repo_name)
            print '\nThis action is IRREVERSIBLE.'
            selection = prompt_user('Proceed?', ['yes', 'no'])
            if (selection == 'yes'):
                do_delete(user_repo_dir, repo_name)
    else:
        sys.stderr.write('Could not find the repository at /users/%s/%s.\n' %
                         (user_repo_dir, repo_name))
        sys.stderr.write('Please check the list at https://%s/users/%s\n' %
                         (cname, user_repo_dir))
        sys.exit(1)
    sys.exit(0)
def edit_repo (cname, repo_name, do_quick_delete):
    if do_quick_delete:
        delete_repo (cname, repo_name, do_quick_delete)
    else:
        action = prompt_user('What would you like to do?', [
            'Delete the repository',
            'Edit the description',
            'Mark repository as non-publishing',
            'Mark repository as publishing',
            ])
        if action == 'Edit the description':
            edit_repo_description(cname, repo_name)
        elif action == 'Delete the repository':
            delete_repo(cname, repo_name, False)
        elif action == 'Mark repository as non-publishig':
            set_repo_publishing(cname, repo_name, False)
        elif action == 'Mark repository as publishing':
            set_repo_publishing(cname, repo_name, True)
    return
def delete_repo(cname, repo_name, do_quick_delete):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    if os.path.exists('%s/users/%s/%s' % (DOC_ROOT, user_repo_dir, repo_name)):
        if do_quick_delete:
            do_delete(user_repo_dir, repo_name)
        else:
            print '\nAre you sure you want to delete /users/%s/%s?' % (user_repo_dir, repo_name)
            print '\nThis action is IRREVERSIBLE.'
            selection = prompt_user('Proceed?', ['yes', 'no'])
            if (selection == 'yes'):
                do_delete(user_repo_dir, repo_name)
    else:
        sys.stderr.write('Could not find the repository at /users/%s/%s.\n' %
                         (user_repo_dir, repo_name))
        sys.stderr.write('Please check the list at https://%s/users/%s\n' %
                         (cname, user_repo_dir))
        sys.exit(1)
    sys.exit(0)
def delete_repo (cname, repo_name, do_quick_delete, verbose=False):
  global doc_root
  user = os.getenv ('USER')
  if(user in verbose_users):
      verbose = True
  user_repo_dir = user.replace ('@', '_')
  url_path = "/users/%s" % user_repo_dir
  if os.path.exists ('%s/users/%s/%s' % (doc_root[cname], user_repo_dir, repo_name)):
    if do_quick_delete:
      do_delete (cname, user_repo_dir, repo_name, verbose)
    else:
      print '\nAre you sure you want to delete /users/%s/%s?' % (user_repo_dir, repo_name)
      print '\nThis action is IRREVERSIBLE.'
      selection = prompt_user ('Proceed?', ['yes', 'no'])
      if (selection == 'yes'):
        do_delete (cname, user_repo_dir, repo_name, verbose)
  else:
    sys.stderr.write ('Could not find the repository at /users/%s/%s.\n' % (user_repo_dir, repo_name))
    sys.stderr.write ('Please check the list at https://%s/users/%s\n' % (cname, user_repo_dir))
    sys.exit (1)
  sys.exit(0)
def edit_repo_description (cname, repo_name):
    global doc_root
    user = os.getenv ('USER')
    user_repo_dir = user.replace ('@', '_')
    print 'You are about to edit the description for hg.mozilla.org/users/%s/%s.' % (user_repo_dir, repo_name)
    print 'If you need to edit the description for a top level repo, please quit now and file an IT bug for it.'
    selection = prompt_user ('Proceed?', ['yes', 'no'])
    if (selection == 'yes'):
        repo_path = get_and_validate_user_repo(cname, repo_name)
        repo_description =  raw_input ('Enter a one line descripton for the repository: ')
        if repo_description == '':
            return

        repo_description = escape(repo_description)

        config_path, config = get_user_repo_config(repo_path)

        if not config.has_section('web'):
            config.add_section('web')

        config.set('web', 'description', repo_description)

        with open(config_path, 'w+') as fh:
            config.write(fh)
예제 #12
0
def make_repo_clone(cname, repo_name, quick_src, source_repo=''):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    source_repo = ''
    if quick_src:
        run_hg_clone(user_repo_dir, repo_name, quick_src)
        fix_user_repo_perms(repo_name)
        # New user repositories are non-publishing by default.
        set_repo_publishing(repo_name, False)
        sys.exit(0)
        return

    print(MAKING_REPO.format(repo=repo_name, user=user, cname=cname,
                             user_dir=user_repo_dir))
    selection = prompt_user('Proceed?', ['yes', 'no'])
    if selection != 'yes':
        return

    print 'You can clone an existing public repo or a users private repo.'
    print 'You can also create an empty repository.'
    selection = prompt_user('Source repository:', [
                            'Clone a public repository',
                            'Clone a private repository',
                            'Create an empty repository'])
    if (selection == 'Clone a public repository'):
        exec_command = "/usr/bin/find " + DOC_ROOT + " -maxdepth 3 -mindepth 2 -type d -name .hg"
        args = shlex.split(exec_command)
        with open(os.devnull, 'wb') as devnull:
            p = Popen(args, stdout=PIPE, stdin=PIPE, stderr=devnull)
            repo_list = p.communicate()[0].split("\n")
        if repo_list:
            print "We have the repo_list"
            repo_list = map(lambda x: x.replace(DOC_ROOT + '/', ''), repo_list)
            repo_list = map(lambda x: x.replace('/.hg', ''), repo_list)
            repo_list = [x.strip() for x in sorted(repo_list) if x.strip()]
            print 'List of available public repos'
            source_repo = prompt_user('Pick a source repo:', repo_list, period=False)
    elif (selection == 'Clone a private repository'):
        source_user = raw_input('Please enter the e-mail address of the user '
                                'owning the repo: ')
        valid_user = is_valid_user(source_user)
        if valid_user == True:
            source_user = source_user.replace('@', '_')
        elif valid_user == False:
            sys.stderr.write('Unknown user.\n')
            sys.exit(1)
        elif valid_user == 'Invalid Email Address':
            sys.stderr.write('Invalid Email Address.\n')
            sys.exit(1)
        source_user_path = run_command('find ' + DOC_ROOT + '/users/' + source_user + ' -maxdepth 1 -mindepth 1 -type d')
        if not source_user_path:
            print 'That user does not have any private repositories.'
            print 'Check https://' + cname + '/users for a list of valid users.'
            sys.exit(1)
        else:
            user_repo_list = run_command('find ' + DOC_ROOT + '/users/' + source_user + ' -maxdepth 3 -mindepth 2 -type d -name .hg')
            user_repo_list = map(lambda x: x.replace(DOC_ROOT + '/users/' + source_user, ''), user_repo_list)
            user_repo_list = map(lambda x: x.replace('/.hg', ''), user_repo_list)
            user_repo_list = map(lambda x: x.strip('/'), user_repo_list)
            user_repo_list = sorted(user_repo_list)
            print 'Select the users repo you wish to clone.'
            source_repo = prompt_user('Pick a source repo:', user_repo_list, period=False)
        source_repo = 'users/' + source_user + '/' + source_repo
    elif (selection == 'Create an empty repository'):
        source_repo = ''
    else:
        # We should not get here
        source_repo = ''
    if source_repo != '':
        print 'About to clone /%s to /users/%s/%s' % (source_repo, user_repo_dir, repo_name)
        response = prompt_user('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
            print 'Please do not interrupt this operation.'
            run_hg_clone(user_repo_dir, repo_name, source_repo)
    else:
        print "About to create an empty repository at /users/%s/%s" % (user_repo_dir, repo_name)
        response = prompt_user('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
            if not os.path.exists('%s/users/%s' % (DOC_ROOT, user_repo_dir)):
                try:
                    exec_command = '/bin/mkdir %s/users/%s' % (DOC_ROOT, user_repo_dir)
                    run_command(exec_command)
                except Exception, e:
                    print "Exception %s" % (e)

            run_command('/usr/bin/nohup %s --config format.usegeneraldelta=true init %s/users/%s/%s' % (HG, DOC_ROOT, user_repo_dir, repo_name))
def make_repo_clone (cname, repo_name, quick_src, verbose=False, source_repo=''):
  global doc_root
  user = os.getenv ('USER')
  user_repo_dir = user.replace ('@', '_')
  dest_url = "/users/%s" % user_repo_dir
  source_repo = ''
  if quick_src:
    if(user in verbose_users):
        verbose=True
        run_hg_clone (cname, user_repo_dir, repo_name, quick_src, True)
    else:
      run_hg_clone (cname, user_repo_dir, repo_name, quick_src)
    fix_user_repo_perms (cname, repo_name)
    sys.exit(0)
  else:
    #make_wsgi_dir(cname, user_repo_dir)
    print "Making repo %s for %s." % (repo_name, user)
    print "This repo will appear as %s/users/%s/%s." % (cname, user_repo_dir, repo_name)
    print 'If you need a top level repo, please quit now and file a bug for IT to create one for you.'
    selection = prompt_user ('Proceed?', ['yes', 'no'])
    if (selection == 'yes'):
      print 'You can clone an existing public repo or a users private repo.'
      print 'You can also create an empty repository.'
      selection = prompt_user ('Source repository:', ['Clone a public repository', 'Clone a private repository', 'Create an empty repository'])
      if (selection == 'Clone a public repository'):
        exec_command = "/usr/bin/find " + doc_root[cname] + " -maxdepth 3 -mindepth 2 -type d -name .hg"
        args = shlex.split(exec_command)
        #repo_list = run_command (exec_command)
        p = Popen(args, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
        repo_list = p.communicate()[0].split("\n")
        if repo_list:
          print "We have the repo_list"
          repo_list = map (lambda x: x.replace (doc_root[cname] + '/', ''), repo_list)
          repo_list = map (lambda x: x.replace ('/.hg', ''), repo_list)
          print 'List of available public repos'
          source_repo = prompt_user ('Pick a source repo:', repo_list)
      elif (selection == 'Clone a private repository'):
        source_user = raw_input ('Please enter the e-mail address of the user owning the repo: ')
        valid_user = is_valid_user(source_user)
        if valid_user == True:
          source_user = source_user.replace ('@', '_')
        elif valid_user == False:
          sys.stderr.write ('Unknown user.\n')
          sys.exit (1)
        elif valid_user == 'Invalid Email Address':
          sys.stderr.write ('Invalid Email Address.\n')
          sys.exit (1)
        source_user_path = run_command ('find ' + doc_root[cname] + '/users/' + source_user + ' -maxdepth 1 -mindepth 1 -type d')
        if not source_user_path:
          print 'That user does not have any private repositories.'
          print 'Check https://' + cname + '/users for a list of valid users.'
          sys.exit (1)
        else:
          user_repo_list = run_command ('find ' + doc_root[cname] + '/users/' + source_user + ' -maxdepth 3 -mindepth 2 -type d -name .hg')
          user_repo_list = map (lambda x: x.replace (doc_root[cname] + '/users/' + source_user, ''), user_repo_list)
          user_repo_list = map (lambda x: x.replace ('/.hg', ''), user_repo_list)
          user_repo_list = map (lambda x: x.strip ('/'), user_repo_list)
          print 'Select the users repo you wish to clone.'
          source_repo = prompt_user ('Pick a source repo:', user_repo_list)
          source_repo = 'users/' + source_user + '/' + source_repo
      elif (selection == 'Create an empty repository'):
        source_repo=''
      else:
          # We should not get here
          source_repo=''
      if source_repo != '':
        print 'About to clone /%s to /users/%s/%s' % (source_repo, user_repo_dir, repo_name)
        response = prompt_user ('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
          print 'Please do not interrupt this operation.'
          run_hg_clone (cname, user_repo_dir, repo_name, source_repo)
      else:
        print "About to create an empty repository at /users/%s/%s" % (user_repo_dir, repo_name)
        response = prompt_user ('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
          if not os.path.exists ('%s/users/%s' % (doc_root[cname], user_repo_dir)):
            try:
              exec_command = '/bin/mkdir %s/users/%s' % (doc_root[cname], user_repo_dir)
              run_command (exec_command)
            except Exception, e:
              print "Exception %s" % (e)

          run_command ('/usr/bin/nohup /usr/bin/hg init %s/users/%s/%s' % (doc_root[cname], user_repo_dir, repo_name))
      fix_user_repo_perms (cname, repo_name)
      sys.exit (0)
def make_repo_clone(cname, repo_name, quick_src, source_repo=''):
    user = os.getenv('USER')
    user_repo_dir = user.replace('@', '_')
    source_repo = ''
    if quick_src:
        run_hg_clone(user_repo_dir, repo_name, quick_src)
        fix_user_repo_perms(repo_name)
        # New user repositories are non-publishing by default.
        set_repo_publishing(repo_name, False)
        sys.exit(0)
        return

    print(MAKING_REPO.format(repo=repo_name, user=user, cname=cname,
                             user_dir=user_repo_dir))
    selection = prompt_user('Proceed?', ['yes', 'no'])
    if selection != 'yes':
        return

    print 'You can clone an existing public repo or a users private repo.'
    print 'You can also create an empty repository.'
    selection = prompt_user('Source repository:', [
                            'Clone a public repository',
                            'Clone a private repository',
                            'Create an empty repository'])
    if (selection == 'Clone a public repository'):
        exec_command = "/usr/bin/find " + DOC_ROOT + " -maxdepth 3 -mindepth 2 -type d -name .hg"
        args = shlex.split(exec_command)
        with open(os.devnull, 'wb') as devnull:
            p = Popen(args, stdout=PIPE, stdin=PIPE, stderr=devnull)
            repo_list = p.communicate()[0].split("\n")
        if repo_list:
            print "We have the repo_list"
            repo_list = map(lambda x: x.replace(DOC_ROOT + '/', ''), repo_list)
            repo_list = map(lambda x: x.replace('/.hg', ''), repo_list)
            repo_list = [x.strip() for x in sorted(repo_list) if x.strip()]
            print 'List of available public repos'
            source_repo = prompt_user('Pick a source repo:', repo_list, period=False)
    elif (selection == 'Clone a private repository'):
        source_user = raw_input('Please enter the e-mail address of the user '
                                'owning the repo: ')
        valid_user = is_valid_user(source_user)
        if valid_user == True:
            source_user = source_user.replace('@', '_')
        elif valid_user == False:
            sys.stderr.write('Unknown user.\n')
            sys.exit(1)
        elif valid_user == 'Invalid Email Address':
            sys.stderr.write('Invalid Email Address.\n')
            sys.exit(1)
        source_user_path = run_command('find ' + DOC_ROOT + '/users/' + source_user + ' -maxdepth 1 -mindepth 1 -type d')
        if not source_user_path:
            print 'That user does not have any private repositories.'
            print 'Check https://' + cname + '/users for a list of valid users.'
            sys.exit(1)
        else:
            user_repo_list = run_command('find ' + DOC_ROOT + '/users/' + source_user + ' -maxdepth 3 -mindepth 2 -type d -name .hg')
            user_repo_list = map(lambda x: x.replace(DOC_ROOT + '/users/' + source_user, ''), user_repo_list)
            user_repo_list = map(lambda x: x.replace('/.hg', ''), user_repo_list)
            user_repo_list = map(lambda x: x.strip('/'), user_repo_list)
            user_repo_list = sorted(user_repo_list)
            print 'Select the users repo you wish to clone.'
            source_repo = prompt_user('Pick a source repo:', user_repo_list, period=False)
        source_repo = 'users/' + source_user + '/' + source_repo
    elif (selection == 'Create an empty repository'):
        source_repo = ''
    else:
        # We should not get here
        source_repo = ''
    if source_repo != '':
        print 'About to clone /%s to /users/%s/%s' % (source_repo, user_repo_dir, repo_name)
        response = prompt_user('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
            print 'Please do not interrupt this operation.'
            run_hg_clone(user_repo_dir, repo_name, source_repo)
    else:
        print "About to create an empty repository at /users/%s/%s" % (user_repo_dir, repo_name)
        response = prompt_user('Proceed?', ['yes', 'no'])
        if (response == 'yes'):
            if not os.path.exists('%s/users/%s' % (DOC_ROOT, user_repo_dir)):
                try:
                    exec_command = '/bin/mkdir %s/users/%s' % (DOC_ROOT, user_repo_dir)
                    run_command(exec_command)
                except Exception, e:
                    print "Exception %s" % (e)

            run_command('/usr/bin/nohup %s init %s/users/%s/%s' % (HG, DOC_ROOT, user_repo_dir, repo_name))