Skip to content
Snippets Groups Projects

Introducing sorting of network table

Merged Moul requested to merge jytou:master into master

Created by: jytou

Added switch -s or --sort to the network command to sort the table using given column names.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 71 73 difficulties(ep)
    72 74
    73 75 elif c.subcmd == "network":
    76 from commands import set_network_sort_keys
    • Author Owner

      It's sad to import here this f() instead at file beginning. I don't see how to do better.

  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 71 73 difficulties(ep)
    72 74
    73 75 elif c.subcmd == "network":
    76 from commands import set_network_sort_keys
    • Author Owner

      May be using only -s or --sort. That's annoying it's not well implemented on CommanLine.

  • Moul
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 74 74 .format(current["powMin"], match_pattern(int(current["powMin"]))[0], diffi["block"], issuers, len(diffi["levels"]),
    75 75 tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")))
    76 76
    77 network_sort_keys = "block,member,diffi,uid".split(",")
    78 def set_network_sort_keys(some_keys):
    79 global network_sort_keys
    • Author Owner

      global is needed to call global variable which is outside this f()?

  • Moul
  • Moul
  • Moul
  • Moul
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 71 73 difficulties(ep)
    72 74
    73 75 elif c.subcmd == "network":
    76 from commands import set_network_sort_keys
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 71 73 difficulties(ep)
    72 74
    73 75 elif c.subcmd == "network":
    76 from commands import set_network_sort_keys
    • Author Owner

      Yep, argparse could be a good candidate. CommandLine is no more maintained since one year.

  • Moul
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 74 74 .format(current["powMin"], match_pattern(int(current["powMin"]))[0], diffi["block"], issuers, len(diffi["levels"]),
    75 75 tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")))
    76 76
    77 network_sort_keys = "block,member,diffi,uid".split(",")
    78 def set_network_sort_keys(some_keys):
    79 global network_sort_keys
    • Author Owner

      Created by: jytou

      Yes it is. Otherwise you'll be creating a local variable.

  • Moul
  • Moul
  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 75 75 tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")))
    76 76
    77 77
    78 network_sort_keys = ["block", "member", "diffi", "uid"]
    79
    80
    81 def set_network_sort_keys(some_keys):
    82 global network_sort_keys
    • Author Owner

      Why do you need to get this variable here? It's used bellow and should works without doing this?

  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 75 75 tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")))
    76 76
    77 77
    78 network_sort_keys = ["block", "member", "diffi", "uid"]
    79
    80
    81 def set_network_sort_keys(some_keys):
    82 global network_sort_keys
    • Author Owner

      Created by: jytou

      The problem is that the keys are used in the callback get_network_sort_key() for which I have no control (it's a callback...). So I somehow need a global variable. We could set it directly from silkaj.py but I figured that doing so through a method would be cleaner.

  • Moul
    Moul @moul started a thread on commit 0149bfa9
  • 75 75 tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")))
    76 76
    77 77
    78 network_sort_keys = ["block", "member", "diffi", "uid"]
    79
    80
    81 def set_network_sort_keys(some_keys):
    82 global network_sort_keys
  • Moul added Feature label and removed enhancement label

    added Feature label and removed enhancement label

  • Please register or sign in to reply
    Loading