Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Invocation
requires -t/--top-num NUMBER where NUMBER > 1
-l, --list print list of mirrors only, don't generate file
cannot be used with -c/--choose
-r, --random pick a random mirror from top list
cannot be used with -c/--choose

The exit code is 0 on success, 1 on error, and 4 if sources.list already has the chosen
mirror and a new one was not generated.
Expand Down
3 changes: 3 additions & 0 deletions apt_select/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""Main apt-select script"""

import random
import requests
import re

Expand Down Expand Up @@ -200,6 +201,8 @@ def set_hostname_len(url, i):
key = 0
if args.choose:
key = get_selected_mirror(len(archives.top_list)) - 1
elif args.random:
key = random.randint(0, len(archives.top_list) - 1)

if args.list_only:
exit()
Expand Down
7 changes: 5 additions & 2 deletions apt_select/apt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from subprocess import check_output
from os import path
from os import path, environ
from apt_select.utils import utf8_decode

SUPPORTED_KERNEL = 'Linux'
Expand Down Expand Up @@ -97,7 +97,7 @@ class Sources(object):

DIRECTORY = '/etc/apt/'
LIST_FILE = 'sources.list'
_CONFIG_PATH = DIRECTORY + LIST_FILE
_CONFIG_PATH = environ.get('APT_CONFIGPATH', DIRECTORY + LIST_FILE)

def __init__(self, codename):
self._codename = codename.lower()
Expand Down Expand Up @@ -157,6 +157,9 @@ def set_current_archives(self):
raise SourcesFileError(err)

urls = self.__get_current_archives()
if 'current' not in urls:
# hardcode a fallback to main ubuntu archive
urls['current'] = 'http://archive.ubuntu.com/ubuntu'
if not urls:
raise SourcesFileError((
"Error finding current %s URI in %s\n%s\n" %
Expand Down
11 changes: 11 additions & 0 deletions apt_select/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def get_args():
),
default=False
)
output_group.add_argument(
'-r',
'--random',
dest='random',
action='store_true',
help=(
"pick a random mirror from top list\n"
"cannot be used with -c/--choose\n"
),
default=False
)

return parser

Expand Down