Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating documentation for Python 3 #544

Open
dwysocki opened this issue Nov 15, 2023 · 3 comments
Open

Updating documentation for Python 3 #544

dwysocki opened this issue Nov 15, 2023 · 3 comments

Comments

@dwysocki
Copy link

There are a lot of Python 2 code examples in the docs. A search for "print " (note the trailing space) finds 29 matching files, some of which are not offenders, but many are, including README.md. Presumably there are other issues as well, but that's the easy one to search.

I can make a pull request with fixes, but I need some info. I see Python 2.7 is still listed as supported, so presumably the examples should be Python 2/3 cross-compatible? Are there any other requirements?

@degremont
Copy link
Collaborator

Thanks @dwysocki ! Honestly, we are thinking of dropping 2.7 support in next release, so I'm not sure there is value in writting examples that are cross-compatible.
Moreover, 2.7 support is there for compatibility for existing code base, not for people writing new projects from scratch.

If you can just send a PR to migrate them to Py3, that would be great!

@dwysocki
Copy link
Author

Here is a task list with every object that has a docstring containing code examples, with line numbers inserted as comments

  • ClusterShell.CLI.Clubak.MsgTree.remove
>>> msgtree.remove(lambda k: k > 3) # line: 5
  • ClusterShell.CLI.Clubak.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.CLI.Clubak.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.CLI.Clush.MsgTree.remove
>>> msgtree.remove(lambda k: k > 3) # line: 5
  • ClusterShell.CLI.Clush.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.CLI.Clush.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.CLI.Clush.Task
>>> task = task_self()                                                  # line: 13
>>> task = Task()                                                       # line: 17
>>> task = Task(thread=thr)                                             # line: 22
>>> task.shell("/bin/hostname")                                         # line: 26
>>> task.shell("/bin/hostname", nodes="tiger[1-20]")                    # line: 30
>>> task.shell("uname -r", nodes="node[1-9]", handler=MyEventHandler()) # line: 39
>>> task.resume()                                                       # line: 44
>>> task.run()                                                          # line: 48
>>> task.run("hostname", nodes="tiger[1-20]", handler=MyEventHandler()) # line: 53
>>> task.run("check_network.sh", nodes="tiger[1-20]", timeout=30)       # line: 61
  • ClusterShell.CLI.Clush.Task.iter_buffers
>>> for buffer, nodelist in task.iter_buffers(): # line: 10
...     print NodeSet.fromlist(nodelist)
...     print buffer
  • ClusterShell.CLI.Clush.Task.run
>>> task.run("hostname", nodes="foo")   # line: 5
>>> task.shell("hostname", nodes="foo") # line: 10
>>> task.shell("hostname", nodes="bar") # line: 11
>>> task.run()                          # line: 12
  • ClusterShell.CLI.Clush.Task.schedule
>>> task = task_self()                                           # line: 7
>>> worker = WorkerSsh("node[2-3]", None, 10, command="/bin/ls") # line: 8
>>> task.schedule(worker)                                        # line: 9
>>> task.resume()                                                # line: 10
  • ClusterShell.CLI.Clush.Task.set_info
>>> task.set_info('fanout', 128) # line: 7
>>> task.set_info('debug', True) # line: 10
  • ClusterShell.CLI.Clush.Task.shell
>>> task = task_self()                            # line: 37
>>> task.shell("/bin/date", nodes="node[1-2345]") # line: 38
>>> task.resume()                                 # line: 39
  • ClusterShell.CLI.Display.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.CLI.Display.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.CLI.Nodeset.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.CLI.Nodeset.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.CLI.Nodeset.RangeSet
>>> rset = RangeSet()            # empty RangeSet                              # line: 8
>>> rset = RangeSet("5,10-42")   # contains '5', '10' to '42'                  # line: 9
>>> rset = RangeSet("0-10/2")    # contains '0', '2', '4', '6', '8', '10'      # line: 10
>>> rset = RangeSet("00-10/2")   # contains '00', '02', '04', '06', '08', '10' # line: 11
>>> RangeSet([3, 6, 8, 7, 1])                                                  # line: 15
>>> rset2 = RangeSet(rset)                                                     # line: 17
  • ClusterShell.CLI.Nodeset.RangeSet.split
>>> RangeSet("1-5").split(3)  # line: 6
  • ClusterShell.Defaults.Defaults
>>> from ClusterShell.Defaults import DEFAULTS                    # line: 33
>>> from ClusterShell.Task import task_self                       # line: 34
>>> # Change default distant worker to rsh (WorkerRsh)            # line: 35
... DEFAULTS.distant_workername = 'rsh'
>>> task = task_self()                                            # line: 37
>>> task.run("uname -r", nodes="cs[01-03]")                       # line: 38
>>> list((str(msg), nodes) for msg, nodes in task.iter_buffers()) # line: 40
  • ClusterShell.Gateway.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Gateway.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Gateway.StreamWorker
>>> worker.set_reader('stream1', fd1) # line: 8
>>> worker.set_writer('stream2', fd2) # line: 9
  • ClusterShell.MsgTree.MsgTree.remove
>>> msgtree.remove(lambda k: k > 3) # line: 5
  • ClusterShell.NodeSet.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.NodeSet.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.NodeSet.NodeSetBase
>>> nsb = NodeSetBase('node%s-ipmi', RangeSet('1-5,7'), False)              # line: 12
>>> str(nsb)                                                                # line: 13
>>> nsb = NodeSetBase('node%s-ib%s', RangeSetND([['1-5,7', '1-2']]), False) # line: 15
>>> str(nsb)                                                                # line: 16
  • ClusterShell.NodeSet.RangeSet
>>> rset = RangeSet()            # empty RangeSet                              # line: 8
>>> rset = RangeSet("5,10-42")   # contains '5', '10' to '42'                  # line: 9
>>> rset = RangeSet("0-10/2")    # contains '0', '2', '4', '6', '8', '10'      # line: 10
>>> rset = RangeSet("00-10/2")   # contains '00', '02', '04', '06', '08', '10' # line: 11
>>> RangeSet([3, 6, 8, 7, 1])                                                  # line: 15
>>> rset2 = RangeSet(rset)                                                     # line: 17
  • ClusterShell.NodeSet.RangeSet.split
>>> RangeSet("1-5").split(3)  # line: 6
  • ClusterShell.Propagation.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Propagation.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.RangeSet.RangeSet
>>> rset = RangeSet()            # empty RangeSet                              # line: 8
>>> rset = RangeSet("5,10-42")   # contains '5', '10' to '42'                  # line: 9
>>> rset = RangeSet("0-10/2")    # contains '0', '2', '4', '6', '8', '10'      # line: 10
>>> rset = RangeSet("00-10/2")   # contains '00', '02', '04', '06', '08', '10' # line: 11
>>> RangeSet([3, 6, 8, 7, 1])                                                  # line: 15
>>> rset2 = RangeSet(rset)                                                     # line: 17
  • ClusterShell.RangeSet.RangeSet.split
>>> RangeSet("1-5").split(3)  # line: 6
  • ClusterShell.Task.MsgTree.remove
>>> msgtree.remove(lambda k: k > 3) # line: 5
  • ClusterShell.Task.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Task.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Task.Task
>>> task = task_self()                                                  # line: 13
>>> task = Task()                                                       # line: 17
>>> task = Task(thread=thr)                                             # line: 22
>>> task.shell("/bin/hostname")                                         # line: 26
>>> task.shell("/bin/hostname", nodes="tiger[1-20]")                    # line: 30
>>> task.shell("uname -r", nodes="node[1-9]", handler=MyEventHandler()) # line: 39
>>> task.resume()                                                       # line: 44
>>> task.run()                                                          # line: 48
>>> task.run("hostname", nodes="tiger[1-20]", handler=MyEventHandler()) # line: 53
>>> task.run("check_network.sh", nodes="tiger[1-20]", timeout=30)       # line: 61
  • ClusterShell.Task.Task.iter_buffers
>>> for buffer, nodelist in task.iter_buffers(): # line: 10
...     print NodeSet.fromlist(nodelist)
...     print buffer
  • ClusterShell.Task.Task.run
>>> task.run("hostname", nodes="foo")   # line: 5
>>> task.shell("hostname", nodes="foo") # line: 10
>>> task.shell("hostname", nodes="bar") # line: 11
>>> task.run()                          # line: 12
  • ClusterShell.Task.Task.schedule
>>> task = task_self()                                           # line: 7
>>> worker = WorkerSsh("node[2-3]", None, 10, command="/bin/ls") # line: 8
>>> task.schedule(worker)                                        # line: 9
>>> task.resume()                                                # line: 10
  • ClusterShell.Task.Task.set_info
>>> task.set_info('fanout', 128) # line: 7
>>> task.set_info('debug', True) # line: 10
  • ClusterShell.Task.Task.shell
>>> task = task_self()                            # line: 37
>>> task.shell("/bin/date", nodes="node[1-2345]") # line: 38
>>> task.resume()                                 # line: 39
  • ClusterShell.Topology.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Topology.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Worker.Popen
>>> worker = WorkerPopen("/bin/uname", key="mykernel") # line: 6
>>> task.schedule(worker)    # schedule worker         # line: 7
>>> task.resume()            # run task                # line: 8
>>> worker.retcode()         # get return code         # line: 9
>>> worker.read()            # read command output     # line: 11
  • ClusterShell.Worker.Exec.ExecWorker
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Exec.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Worker.Exec.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Worker.Exec.WORKER_CLASS
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Pdsh.ExecWorker
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Pdsh.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Worker.Pdsh.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Worker.Pdsh.WORKER_CLASS
>>> worker = WorkerPdsh(nodeset, handler=MyEventHandler(),     # line: 4
...                     timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerPdsh(nodeset, handler=MyEventHandler(),     # line: 10
...                     timeout=30, source="/etc/my.conf",
...                     dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Pdsh.WorkerPdsh
>>> worker = WorkerPdsh(nodeset, handler=MyEventHandler(),     # line: 4
...                     timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerPdsh(nodeset, handler=MyEventHandler(),     # line: 10
...                     timeout=30, source="/etc/my.conf",
...                     dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Rsh.ExecWorker
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Rsh.WORKER_CLASS
>>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),      # line: 4
...                    timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),      # line: 10
...                     source="/etc/my.conf",
...                     dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Rsh.WorkerRsh
>>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),      # line: 4
...                    timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),      # line: 10
...                     source="/etc/my.conf",
...                     dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Ssh.ExecWorker
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Ssh.WORKER_CLASS
>>> worker = WorkerSsh(nodeset, handler=MyEventHandler(),      # line: 4
...                    timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerSsh(nodeset, handler=MyEventHandler(),      # line: 10
...                    timeout=30, source="/etc/my.conf",
...                    dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Ssh.WorkerSsh
>>> worker = WorkerSsh(nodeset, handler=MyEventHandler(),      # line: 4
...                    timeout=30, command="/bin/hostname")
>>> task.schedule(worker)      # schedule worker for execution # line: 6
>>> task.resume()              # run                           # line: 7
>>> worker = WorkerSsh(nodeset, handler=MyEventHandler(),      # line: 10
...                    timeout=30, source="/etc/my.conf",
...                    dest="/etc/my.conf")
>>> task.schedule(worker)      # schedule worker for execution # line: 13
>>> task.resume()              # run                           # line: 14
  • ClusterShell.Worker.Tree.ExecWorker
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 9
...                     timeout=30, command="/bin/uptime")
>>> task.schedule(worker)   # schedule worker for execution    # line: 11
>>> task.run()              # run                              # line: 12
>>> worker = ExecWorker(nodeset, handler=MyEventHandler(),     # line: 16
...                     source="/etc/my.cnf",
...                     dest="/etc/my.cnf.bak")
>>> task.schedule(worker)      # schedule worker for execution # line: 19
>>> task.run()                 # run                           # line: 20
  • ClusterShell.Worker.Tree.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Worker.Tree.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Worker.Tree.tempfile
>>> tempfile.mkstemp()           # line: 11
>>> tempfile.mkdtemp(suffix=b'') # line: 13
  • ClusterShell.Worker.Worker.NodeSet
>>> nodeset = NodeSet()               # empty NodeSet           # line: 5
>>> nodeset = NodeSet("cluster3")     # contains only cluster3  # line: 6
>>> nodeset = NodeSet("cluster[5,10-42]")                       # line: 7
>>> nodeset = NodeSet("cluster[0-10/2]")                        # line: 8
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]") # line: 9
>>> nodeset = NodeSet("blue[1-50]")                             # line: 18
>>> nodeset.remove("blue[36-40]")                               # line: 19
>>> print nodeset                                               # line: 20
>>> nodeset = NodeSet("node[0-10],node[14-16]") # union         # line: 31
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference    # line: 32
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection  # line: 33
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor           # line: 34
  • ClusterShell.Worker.Worker.NodeSet.split
>>> for nodeset in NodeSet("foo[1-5]").split(3): # line: 5
...     print nodeset
  • ClusterShell.Worker.Worker.StreamWorker
>>> worker.set_reader('stream1', fd1) # line: 8
>>> worker.set_writer('stream2', fd2) # line: 9
  • ClusterShell.Worker.Worker.Worker
>>> from ClusterShell.Event import EventHandler      # line: 18
>>> class MyOutputHandler(EventHandler):             # line: 19
...     def ev_read(self, worker, node, sname, msg):
...             print "%s: %s" % (node, line)

@dwysocki
Copy link
Author

For future reference, this is the script I wrote to generate that list, in case it's useful to anybody (credit to Bing AI for writing the initial draft)

import doctest
import inspect
import importlib
import pkgutil

import ClusterShell


def get_docstrings(module):
    result = {}

    def store(name, val):
        if val:
            result[name] = val

    for name, obj in inspect.getmembers(module):
        if inspect.isclass(obj) or inspect.isfunction(obj) or inspect.ismodule(obj):
            store(f"{module.__name__}.{name}", get_examples(module.__name__, name, obj.__doc__))

        if inspect.isclass(obj):
            for method_name, method_obj in inspect.getmembers(obj):
                if inspect.isfunction(method_obj):
                    store(f"{module.__name__}.{name}.{method_name}", get_examples(module.__name__, f'{name}.{method_name}', method_obj.__doc__))

    if hasattr(module, '__path__'):
        for _, submodule_name, _ in pkgutil.iter_modules(module.__path__):
            result.update(get_docstrings(importlib.import_module(f'{module.__name__}.{submodule_name}')))

    return result


def get_examples(module_name, obj_name, docstring):
    if docstring:
        return doctest.DocTestParser().get_examples(docstring)


def print_examples(examples):
    source_width = max(max(len(line) for line in ex.source.splitlines())
                       for ex in examples)

    for ex in examples:
        for i, line in enumerate(ex.source.splitlines()):
            if i == 0:
                print(">>>", line.ljust(source_width), "# line:", ex.lineno)
            else:
                print("...", line)


def main():
    docstrings = get_docstrings(ClusterShell)

    for name, examples in docstrings.items():
        print(f"- [ ] `{name}`")
        print("```python")
        print_examples(examples)
        print("```")


if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants