Skip to content

Commit

Permalink
trying to implement main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy committed Apr 26, 2024
1 parent 802b093 commit e5af31d
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions pydfuutil/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
(C) 2023 Yaroshenko Dmytro (https://github.com/o-murphy)
Based on existing code of dfu-programmer-0.4
"""
import argparse
import errno
import re
import sys
from typing import Any, Callable

import usb.core

from pydfuutil import __version__, __copyright__, dfu

MAX_DESC_STR_LEN = 253

VERBOSE = False

# TODO: not implemented yet

Expand Down Expand Up @@ -96,7 +98,6 @@ def _get_first_cb(dif: dfu.DfuIf, v: dfu.DfuIf) -> int:
return 1



def _get_first_dfu_if(dif: dfu.DfuIf) -> int:
"""
Fills in dif with the first found DFU interface.
Expand Down Expand Up @@ -189,7 +190,6 @@ def get_alt_name(dfu_if: dfu.DfuIf) -> [int, str]:
return -1



def print_dfu_if(dfu_if: dfu.DfuIf, v: Any) -> int:
"""
Print DFU interface information.
Expand Down Expand Up @@ -456,7 +456,7 @@ def usb_get_any_descriptor(dev: usb.core.Device,

# Suck in the configuration descriptor list from device
cbuf = dev.ctrl_transfer(usb.util.ENDPOINT_IN, usb.util.GET_DESCRIPTOR,
(usb.util.DESC_TYPE_CONFIG << 8) | 0, 0, conflen)
(usb.util.DESC_TYPE_CONFIG << 8) | 0, 0, conflen)

if len(cbuf) < conflen:
print("Warning: failed to retrieve complete configuration descriptor, got {}/{}".format(len(cbuf), conflen))
Expand All @@ -472,7 +472,7 @@ def usb_get_any_descriptor(dev: usb.core.Device,
# Finally try to retrieve it requesting the device directly
# This is not supported on all devices for non-standard types
return dev.ctrl_transfer(usb.util.ENDPOINT_IN, usb.util.GET_DESCRIPTOR,
(desc_type << 8) | desc_index, 0, resbuf, res_len)
(desc_type << 8) | desc_index, 0, resbuf, res_len)


def get_cached_extra_descriptor(dev: usb.core.Device,
Expand Down Expand Up @@ -550,26 +550,28 @@ def help_() -> None:
)


def print_version() -> None:
print(f"{__version__}\n\n")
print('Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.\n'
f'{__copyright__}\n'
'This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n')
VERSION = (f"{__version__}\n\n"
f"('Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.\n')"
f"{__copyright__}\n"
f"This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n')")


def main(argv):
def main() -> None:
# Todo: implement

global VERBOSE

# Create argument parser
parser = argparse.ArgumentParser(description="Description of your program")

# Add arguments
parser.add_argument("-h", "--help", action="store_true", help="Show this help message and exit")
parser.add_argument("-V", "--version", action="store_true", help="Show version information and exit")
parser.add_argument("-V", "--version", action="version", version=VERSION,
help="Show version information and exit")
parser.add_argument("-v", "--verbose", action="store_true", help="Increase verbosity")
parser.add_argument("-l", "--list", action="store_true", help="List option")
parser.add_argument("-e", "--erase", action="store_true", help="Erase option")
parser.add_argument("-d", "--download", metavar="FILE", help="Download option with argument")
parser.add_argument("-e", "--detach", action="store_true", help="Erase option")
parser.add_argument("-d", "--device", metavar="FILE", help="Download option with argument")
parser.add_argument("-p", "--path", metavar="PATH", help="Path option with argument")
parser.add_argument("-c", "--config", metavar="CONFIG", help="Config option with argument")
parser.add_argument("-i", "--interface", metavar="INTERFACE", help="Interface option with argument")
Expand All @@ -583,15 +585,28 @@ def main(argv):
# Parse arguments
args = parser.parse_args()

if args.h:
help_()
sys.exit(0)

while 1:
c, option_index = 0, 0
if args.version:
print(VERSION)

if args.verbose:
VERBOSE = True

raise NotImplementedError
if args.list:
mode = MODE_LIST

if args.detach:
mode = MODE_DETACH

if __name__ == '__main__':
import sys
if args.device:
device_id_filter = args.device

if args.path:
dif.path = args.path

main(sys.argv)

if __name__ == '__main__':
main()

0 comments on commit e5af31d

Please sign in to comment.