Re: Python 2 to 3 conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick O'Callaghan wrote:
> On Tue, 2024-11-19 at 14:01 +0000, Will McDonald wrote:
>> On Tue, 19 Nov 2024 at 14:00, Will McDonald <wmcdonald@xxxxxxxxx> wrote:
>> 
>>> On Tue, 19 Nov 2024 at 13:45, Patrick O'Callaghan <pocallaghan@xxxxxxxxx>
>>> wrote:
>>> 
>>>> I'm attempting to convert a small Python-2 script to Python-3.
>>>> 
>>> 
>> By the way, is this script something you can stick in a pastebin/gist or
>> similar and share?
>> 
>> If it's genuinely small, it might be trivial to rewrite?
> 
> You can find the script at:
> 
> https://github.com/zepalmer/script-vdr
> 
> It's quite old but I found it useful with X11. I'm interested in trying
> it under Wayland as a workaround for the broken session restore in
> Plasma. Hopefully it will work with XWayland.

A quick git clone and run of `2to3-3.12 -w vdr` made only 3
minor changes, after which `./vdr --help` ran without error.
That's not a great test, but it does mean python3 can parse
the script okay.  There might be other issues to work out to
run it for real, but it's short enough that it should be
relatively easy to do, if you're mildly familiar with python
(or programming lanugages in general).

    $ git diff
    diff --git a/vdr b/vdr
    index dd4c2c8..9763b9a 100755
    --- a/vdr
    +++ b/vdr
    @@ -43,7 +43,7 @@ def parse_args():
             display_help_and_exit("Only one of --load or --save may be specified.")

         if not os.path.exists("/proc/%d" % args.pid):
    -        print("Invalid PID: %d" % args.pid)
    +        print(("Invalid PID: %d" % args.pid))
             sys.exit(2)

         name = args.name if args.name else os.path.realpath("/proc/%d/exe" % args.pid)
    @@ -109,7 +109,7 @@ def save_action(pid, name):
         application_data = load_data()
         new_windows_for_pid = get_window_data(pid)
         windows_for_pid = application_data.get(name, {})
    -    for value in new_windows_for_pid.values():
    +    for value in list(new_windows_for_pid.values()):
             del value["window_id"]
         windows_for_pid.update(new_windows_for_pid)
         application_data[name] = windows_for_pid
    @@ -122,7 +122,7 @@ def load_action(pid, name):
         application_data = load_data()
         windows_for_pid = get_window_data(pid)
         window_data = application_data.get(name, {})
    -    for window_title in windows_for_pid.keys():
    +    for window_title in list(windows_for_pid.keys()):
             try:
                 desktop_id = window_data[window_title]["desktop"]
             except KeyError:


-- 
Todd

Attachment: signature.asc
Description: PGP signature

-- 
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux