fastdupes icon indicating copy to clipboard operation
fastdupes copied to clipboard

Python 3 support

Open wolph opened this issue 8 years ago • 2 comments

As far as I can see it would only change a few print statements and a str/basestr change. The patch as far as I can gather:

@@ -106,7 +106,7 @@
         in
     """
     fhash, read = hashlib.sha1(), 0
-    if isinstance(handle, basestring):
+    if isinstance(handle, str):
         handle = file(handle, 'rb')

     if limit:
@@ -250,7 +250,7 @@
                       pos + 1, group_count, fun_desc, count, len(paths)
                   ))

-        for key, group in classifier(paths, *args, **kwargs).items():
+        for key, group in list(classifier(paths, *args, **kwargs).items()):
             groups.setdefault(key, set()).update(group)
             count += len(group)

@@ -439,11 +439,11 @@
     :rtype: :class:`~__builtins__.int`
     """
     dupeList = sorted(dupeList)
-    print
+    print()
     for pos, val in enumerate(dupeList):
-        print "%d) %s" % (pos + 1, val)
+        print("%d) %s" % (pos + 1, val))
     while True:
-        choice = raw_input("[%s/%s] Keepers: " % (mainPos, mainLen)).strip()
+        choice = input("[%s/%s] Keepers: " % (mainPos, mainLen)).strip()
         if not choice:
             print ("Please enter a space/comma-separated list of numbers or "
                    "'all'.")
@@ -495,7 +495,7 @@
         value = DEFAULTS[key]
         if isinstance(value, (list, set)):
             value = ', '.join(value)
-        print "%*s: %s" % (maxlen, key, value)
+        print("%*s: %s" % (maxlen, key, value))

 def delete_dupes(groups, prefer_list=None, interactive=True, dry_run=False):
     """Code to handle the :option:`--delete` command-line option.
@@ -530,7 +530,7 @@

         assert preferred  # Safety check
         for path in pruneList:
-            print "Removing %s" % path
+            print("Removing %s" % path)
             if not dry_run:
                 os.remove(path)

@@ -598,8 +598,8 @@
         delete_dupes(groups, opts.prefer, not opts.noninteractive,
                      opts.dry_run)
     else:
-        for dupeSet in groups.values():
-            print '\n'.join(dupeSet) + '\n'
+        for dupeSet in list(groups.values()):
+            print('\n'.join(dupeSet) + '\n')

 if __name__ == '__main__':
     main()

wolph avatar Jul 07 '17 10:07 wolph

Probably. It's more that this project got put on the back burner before I started making a concerted effort to support Python 3.

I'm just recovering from the tail end of a cold that ended up rolling on into some nasty insomnia, but I'll leave this open and take a look as soon as I've finished catching up from that mess.

ssokolow avatar Jul 07 '17 11:07 ssokolow

Sorry for going silent for so long.

I've started clearing out my backlogged issues now and the actual problem isn't that there aren't Python 3.x fixes, it's that I forgot to test and merge the missingfix branch where they exist.

I'll aim to get to work on that as soon as I get some responses to my comments on PR #32

ssokolow avatar Aug 20 '17 05:08 ssokolow