[Python-modules-commits] [wifi] 13/13: Change name of wifi binary

Ethan Ward ethanward-guest at moszumanska.debian.org
Fri Aug 11 22:30:37 UTC 2017


This is an automated email from the git hooks/post-receive script.

ethanward-guest pushed a commit to branch master
in repository wifi.

commit c74ac48e317a477f58ff7da41ba19b5a61d0cdf3
Author: Ethan Ward <ethan.ward at mycroft.ai>
Date:   Fri Aug 11 17:27:56 2017 -0500

    Change name of wifi binary
---
 debian/patches/0004-Change-name-of-binary.patch | 433 ++++++++++++++++++++++++
 debian/patches/series                           |   1 +
 debian/{wifi.1 => wifi-helper.1}                |   0
 debian/wifi-python-wrapper.install              |   2 +-
 4 files changed, 435 insertions(+), 1 deletion(-)

diff --git a/debian/patches/0004-Change-name-of-binary.patch b/debian/patches/0004-Change-name-of-binary.patch
new file mode 100644
index 0000000..376820b
--- /dev/null
+++ b/debian/patches/0004-Change-name-of-binary.patch
@@ -0,0 +1,433 @@
+From: Ethan Ward <ethan.ward at mycroft.ai>
+Date: Fri, 11 Aug 2017 17:25:08 -0500
+Subject: Change name of binary
+
+---
+ bin/wifi        | 205 --------------------------------------------------------
+ bin/wifi-helper | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 205 insertions(+), 205 deletions(-)
+ delete mode 100755 bin/wifi
+ create mode 100755 bin/wifi-helper
+
+diff --git a/bin/wifi b/bin/wifi
+deleted file mode 100755
+index c540f13..0000000
+--- a/bin/wifi
++++ /dev/null
+@@ -1,205 +0,0 @@
+-#!/usr/bin/python3
+-from __future__ import print_function
+-import argparse
+-import sys
+-import os
+-
+-from wifi import Cell, Scheme
+-from wifi.utils import print_table, match as fuzzy_match
+-from wifi.exceptions import ConnectionError, InterfaceError
+-
+-try:  # Python 2.x
+-    input = raw_input
+-except NameError:
+-    pass
+-
+-
+-def fuzzy_find_cell(interface, query):
+-    match_partial = lambda cell: fuzzy_match(query, cell.ssid)
+-
+-    matches = Cell.where(interface, match_partial)
+-
+-    num_unique_matches = len(set(cell.ssid for cell in matches))
+-    assert num_unique_matches > 0, "Couldn't find a network that matches '{}'".format(query)
+-    assert num_unique_matches < 2, "Found more than one network that matches '{}'".format(query)
+-
+-    # Several cells of the same SSID
+-    if len(matches) > 1:
+-        matches.sort(key=lambda cell: cell.signal)
+-
+-    return matches[0]
+-
+-
+-def find_cell(interface, query):
+-    cell = Cell.where(interface, lambda cell: cell.ssid.lower() == query.lower())
+-
+-    try:
+-        cell = cell[0]
+-    except IndexError:
+-        cell = fuzzy_find_cell(interface, query)
+-    return cell
+-
+-
+-def get_scheme_params(interface, scheme, ssid=None):
+-    cell = find_cell(interface, ssid or scheme)
+-    passkey = None if not cell.encrypted else input('passkey> ')
+-
+-    return interface, scheme, cell, passkey
+-
+-
+-def scan_command(args):
+-    print_table([[cell.signal, cell.ssid, 'protected' if cell.encrypted else 'unprotected'] for cell in Cell.all(args.interface)])
+-
+-
+-def list_command(args):
+-    for scheme in Scheme.for_file(args.file).all():
+-        print(scheme.name)
+-
+-
+-def show_command(args):
+-    scheme = Scheme.for_file(args.file).for_cell(*get_scheme_params(args.interface, args.scheme, args.ssid))
+-    print(scheme)
+-
+-
+-def add_command(args):
+-    scheme_class = Scheme.for_file(args.file)
+-    assert not scheme_class.find(args.interface, args.scheme), "That scheme has already been used"
+-
+-    scheme = scheme_class.for_cell(*get_scheme_params(args.interface, args.scheme, args.ssid))
+-    scheme.save()
+-
+-
+-def connect_command(args):
+-    scheme_class = Scheme.for_file(args.file)
+-    if args.adhoc:
+-        # ensure that we have the adhoc utility scheme
+-        try:
+-            adhoc_scheme = scheme_class(args.interface, 'adhoc')
+-            adhoc_scheme.save()
+-        except AssertionError:
+-            pass
+-        except IOError:
+-            assert False, "Can't write on {0!r}, do you have required privileges?".format(args.file)
+-
+-        scheme = scheme_class.for_cell(*get_scheme_params(args.interface, 'adhoc', args.scheme))
+-    else:
+-        scheme = scheme_class.find(args.interface, args.scheme)
+-        assert scheme, "Couldn't find a scheme named {0!r}, did you mean to use -a?".format(args.scheme)
+-
+-    try:
+-        scheme.activate()
+-    except ConnectionError:
+-        assert False, "Failed to connect to %s." % scheme.name
+-
+-
+-def autoconnect_command(args):
+-    ssids = [cell.ssid for cell in Cell.all(args.interface)]
+-
+-    for scheme in Scheme.all():
+-        # TODO: make it easier to get the SSID off of a scheme.
+-        ssid = scheme.options.get('wpa-ssid', scheme.options.get('wireless-essid'))
+-        if ssid in ssids:
+-            sys.stderr.write('Connecting to "%s".\n' % ssid)
+-            try:
+-                scheme.activate()
+-            except ConnectionError:
+-                assert False, "Failed to connect to %s." % scheme.name
+-            break
+-    else:
+-        assert False, "Couldn't find any schemes that are currently available."
+-
+-
+-def arg_parser():
+-    parser = argparse.ArgumentParser()
+-    parser.add_argument('-i',
+-                        '--interface',
+-                        default='wlan0',
+-                        help="Specifies which interface to use (wlan0, eth0, etc.)")
+-    parser.add_argument('-f',
+-                        '--file',
+-                        default='/etc/network/interfaces',
+-                        help="Specifies which file for scheme storage.")
+-    
+-    subparsers = parser.add_subparsers(title='commands')
+-    
+-    parser_scan = subparsers.add_parser('scan', help="Shows a list of available networks.")
+-    parser_scan.set_defaults(func=scan_command)
+-    
+-    parser_list = subparsers.add_parser('list', help="Shows a list of networks already configured.")
+-    parser_list.set_defaults(func=list_command)
+-    
+-    scheme_help = ("A memorable nickname for a wireless network."
+-                   "  If SSID is not provided, the network will be guessed using SCHEME.")
+-    ssid_help = ("The SSID for the network to which you wish to connect."
+-                 "  This is fuzzy matched, so you don't have to be precise.")
+-    
+-    parser_show = subparsers.add_parser('config',
+-                                        help="Prints the configuration to connect to a new network.")
+-    parser_show.add_argument('scheme', help=scheme_help, metavar='SCHEME')
+-    parser_show.add_argument('ssid', nargs='?', help=ssid_help, metavar='SSID')
+-    parser_show.set_defaults(func=show_command)
+-    
+-    parser_add = subparsers.add_parser('add',
+-                                       help="Adds the configuration to connect to a new network.")
+-    parser_add.add_argument('scheme', help=scheme_help, metavar='SCHEME')
+-    parser_add.add_argument('ssid', nargs='?', help=ssid_help, metavar='SSID')
+-    parser_add.set_defaults(func=add_command)
+-    
+-    parser_connect = subparsers.add_parser('connect',
+-                                           help="Connects to the network corresponding to SCHEME")
+-    parser_connect.add_argument('scheme',
+-                                help="The nickname of the network to which you wish to connect.",
+-                                metavar='SCHEME')
+-    parser_connect.add_argument('-a',
+-                                '--ad-hoc',
+-                                dest='adhoc',
+-                                action="store_true",
+-                                help="Connect to a network without storing it in the config file")
+-    parser_connect.set_defaults(func=connect_command)
+-    
+-    
+-    # TODO: how to specify the correct interfaces file to work off of.
+-    parser_connect.get_options = lambda: [scheme.name for scheme in Scheme.all()]
+-
+-    parser_autoconnect = subparsers.add_parser(
+-        'autoconnect',
+-        help="Searches for saved schemes that are currently"
+-             " available and connects to the first one it finds."
+-    )
+-    parser_autoconnect.set_defaults(func=autoconnect_command)
+-
+-    return parser, subparsers
+-
+-
+-def autocomplete(position, wordlist, subparsers):
+-    if position == 1:
+-        ret = subparsers.choices.keys()
+-    else:
+-        try:
+-            prev = wordlist[position - 1]
+-            ret = subparsers.choices[prev].get_options()
+-        except (IndexError, KeyError, AttributeError):
+-            ret = []
+-
+-    print(' '.join(ret))
+-
+-
+-if __name__ == "__main__":
+-    parser, subparsers = arg_parser()
+-
+-    if len(sys.argv) == 1:
+-        argv = ['scan']
+-    else:
+-        argv = sys.argv[1:]
+-
+-    args = parser.parse_args(argv)
+-
+-    try:
+-        if 'WIFI_AUTOCOMPLETE' in os.environ:
+-            autocomplete(int(os.environ['COMP_CWORD']),
+-                         os.environ['COMP_WORDS'].split(), subparsers)
+-        else:
+-            args.func(args)
+-    except (AssertionError, InterfaceError) as e:
+-        sys.stderr.write("Error: ")
+-        sys.exit(e)
+diff --git a/bin/wifi-helper b/bin/wifi-helper
+new file mode 100755
+index 0000000..c540f13
+--- /dev/null
++++ b/bin/wifi-helper
+@@ -0,0 +1,205 @@
++#!/usr/bin/python3
++from __future__ import print_function
++import argparse
++import sys
++import os
++
++from wifi import Cell, Scheme
++from wifi.utils import print_table, match as fuzzy_match
++from wifi.exceptions import ConnectionError, InterfaceError
++
++try:  # Python 2.x
++    input = raw_input
++except NameError:
++    pass
++
++
++def fuzzy_find_cell(interface, query):
++    match_partial = lambda cell: fuzzy_match(query, cell.ssid)
++
++    matches = Cell.where(interface, match_partial)
++
++    num_unique_matches = len(set(cell.ssid for cell in matches))
++    assert num_unique_matches > 0, "Couldn't find a network that matches '{}'".format(query)
++    assert num_unique_matches < 2, "Found more than one network that matches '{}'".format(query)
++
++    # Several cells of the same SSID
++    if len(matches) > 1:
++        matches.sort(key=lambda cell: cell.signal)
++
++    return matches[0]
++
++
++def find_cell(interface, query):
++    cell = Cell.where(interface, lambda cell: cell.ssid.lower() == query.lower())
++
++    try:
++        cell = cell[0]
++    except IndexError:
++        cell = fuzzy_find_cell(interface, query)
++    return cell
++
++
++def get_scheme_params(interface, scheme, ssid=None):
++    cell = find_cell(interface, ssid or scheme)
++    passkey = None if not cell.encrypted else input('passkey> ')
++
++    return interface, scheme, cell, passkey
++
++
++def scan_command(args):
++    print_table([[cell.signal, cell.ssid, 'protected' if cell.encrypted else 'unprotected'] for cell in Cell.all(args.interface)])
++
++
++def list_command(args):
++    for scheme in Scheme.for_file(args.file).all():
++        print(scheme.name)
++
++
++def show_command(args):
++    scheme = Scheme.for_file(args.file).for_cell(*get_scheme_params(args.interface, args.scheme, args.ssid))
++    print(scheme)
++
++
++def add_command(args):
++    scheme_class = Scheme.for_file(args.file)
++    assert not scheme_class.find(args.interface, args.scheme), "That scheme has already been used"
++
++    scheme = scheme_class.for_cell(*get_scheme_params(args.interface, args.scheme, args.ssid))
++    scheme.save()
++
++
++def connect_command(args):
++    scheme_class = Scheme.for_file(args.file)
++    if args.adhoc:
++        # ensure that we have the adhoc utility scheme
++        try:
++            adhoc_scheme = scheme_class(args.interface, 'adhoc')
++            adhoc_scheme.save()
++        except AssertionError:
++            pass
++        except IOError:
++            assert False, "Can't write on {0!r}, do you have required privileges?".format(args.file)
++
++        scheme = scheme_class.for_cell(*get_scheme_params(args.interface, 'adhoc', args.scheme))
++    else:
++        scheme = scheme_class.find(args.interface, args.scheme)
++        assert scheme, "Couldn't find a scheme named {0!r}, did you mean to use -a?".format(args.scheme)
++
++    try:
++        scheme.activate()
++    except ConnectionError:
++        assert False, "Failed to connect to %s." % scheme.name
++
++
++def autoconnect_command(args):
++    ssids = [cell.ssid for cell in Cell.all(args.interface)]
++
++    for scheme in Scheme.all():
++        # TODO: make it easier to get the SSID off of a scheme.
++        ssid = scheme.options.get('wpa-ssid', scheme.options.get('wireless-essid'))
++        if ssid in ssids:
++            sys.stderr.write('Connecting to "%s".\n' % ssid)
++            try:
++                scheme.activate()
++            except ConnectionError:
++                assert False, "Failed to connect to %s." % scheme.name
++            break
++    else:
++        assert False, "Couldn't find any schemes that are currently available."
++
++
++def arg_parser():
++    parser = argparse.ArgumentParser()
++    parser.add_argument('-i',
++                        '--interface',
++                        default='wlan0',
++                        help="Specifies which interface to use (wlan0, eth0, etc.)")
++    parser.add_argument('-f',
++                        '--file',
++                        default='/etc/network/interfaces',
++                        help="Specifies which file for scheme storage.")
++    
++    subparsers = parser.add_subparsers(title='commands')
++    
++    parser_scan = subparsers.add_parser('scan', help="Shows a list of available networks.")
++    parser_scan.set_defaults(func=scan_command)
++    
++    parser_list = subparsers.add_parser('list', help="Shows a list of networks already configured.")
++    parser_list.set_defaults(func=list_command)
++    
++    scheme_help = ("A memorable nickname for a wireless network."
++                   "  If SSID is not provided, the network will be guessed using SCHEME.")
++    ssid_help = ("The SSID for the network to which you wish to connect."
++                 "  This is fuzzy matched, so you don't have to be precise.")
++    
++    parser_show = subparsers.add_parser('config',
++                                        help="Prints the configuration to connect to a new network.")
++    parser_show.add_argument('scheme', help=scheme_help, metavar='SCHEME')
++    parser_show.add_argument('ssid', nargs='?', help=ssid_help, metavar='SSID')
++    parser_show.set_defaults(func=show_command)
++    
++    parser_add = subparsers.add_parser('add',
++                                       help="Adds the configuration to connect to a new network.")
++    parser_add.add_argument('scheme', help=scheme_help, metavar='SCHEME')
++    parser_add.add_argument('ssid', nargs='?', help=ssid_help, metavar='SSID')
++    parser_add.set_defaults(func=add_command)
++    
++    parser_connect = subparsers.add_parser('connect',
++                                           help="Connects to the network corresponding to SCHEME")
++    parser_connect.add_argument('scheme',
++                                help="The nickname of the network to which you wish to connect.",
++                                metavar='SCHEME')
++    parser_connect.add_argument('-a',
++                                '--ad-hoc',
++                                dest='adhoc',
++                                action="store_true",
++                                help="Connect to a network without storing it in the config file")
++    parser_connect.set_defaults(func=connect_command)
++    
++    
++    # TODO: how to specify the correct interfaces file to work off of.
++    parser_connect.get_options = lambda: [scheme.name for scheme in Scheme.all()]
++
++    parser_autoconnect = subparsers.add_parser(
++        'autoconnect',
++        help="Searches for saved schemes that are currently"
++             " available and connects to the first one it finds."
++    )
++    parser_autoconnect.set_defaults(func=autoconnect_command)
++
++    return parser, subparsers
++
++
++def autocomplete(position, wordlist, subparsers):
++    if position == 1:
++        ret = subparsers.choices.keys()
++    else:
++        try:
++            prev = wordlist[position - 1]
++            ret = subparsers.choices[prev].get_options()
++        except (IndexError, KeyError, AttributeError):
++            ret = []
++
++    print(' '.join(ret))
++
++
++if __name__ == "__main__":
++    parser, subparsers = arg_parser()
++
++    if len(sys.argv) == 1:
++        argv = ['scan']
++    else:
++        argv = sys.argv[1:]
++
++    args = parser.parse_args(argv)
++
++    try:
++        if 'WIFI_AUTOCOMPLETE' in os.environ:
++            autocomplete(int(os.environ['COMP_CWORD']),
++                         os.environ['COMP_WORDS'].split(), subparsers)
++        else:
++            args.func(args)
++    except (AssertionError, InterfaceError) as e:
++        sys.stderr.write("Error: ")
++        sys.exit(e)
diff --git a/debian/patches/series b/debian/patches/series
index 23f06c0..0acb835 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 0001-Remove-broken-tests.patch
 0002-Remove-binary-from-setup.py.patch
 0003-Change-binary-to-python3.patch
+0004-Change-name-of-binary.patch
diff --git a/debian/wifi.1 b/debian/wifi-helper.1
similarity index 100%
rename from debian/wifi.1
rename to debian/wifi-helper.1
diff --git a/debian/wifi-python-wrapper.install b/debian/wifi-python-wrapper.install
index b39eca2..a4d4e93 100644
--- a/debian/wifi-python-wrapper.install
+++ b/debian/wifi-python-wrapper.install
@@ -1 +1 @@
-bin/wifi /usr/bin/
+bin/wifi-helper /usr/bin/

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/wifi.git



More information about the Python-modules-commits mailing list