dirsync icon indicating copy to clipboard operation
dirsync copied to clipboard

Code explanation...

Open tkhyn opened this issue 8 years ago • 1 comments

Original report by Marc Otten (Bitbucket: marcuzzz, GitHub: marcuzzz).


Hi,

I'm playing with you dirsync and it's working great. There is one part I don't understand:

Can you explain what is happening when this code is used: It doesn't feels efficient.

Line:258

#!python

for f1 in self._dcmp.common:
            try:
                st = os.stat(os.path.join(self._dir1, f1))
            except os.error:
                   continue

            if stat.S_ISREG(st.st_mode):
                if updatefunc:
                    updatefunc(f1, self._dir1, self._dir2)

And a bit later:

Line:375

#!python

try:
                st1 = os.stat(file1)
                st2 = os.stat(file2)
            except os.error:
                return -1

FYI I've added threading for left and right:

#!python


#added import
import threading


#added function to class
    def launch_thread_with_message(self,target, message, args=[], kwargs={}):
        def target_with_msg(*args, **kwargs):
            target(*args, **kwargs)
            self.log(message,4)
        thread = threading.Thread(target=target_with_msg, args=args, kwargs=kwargs)
        thread.start()
        return thread

# added to _compare function:

global left,right

if what == "left":
#...

if what == "right":
#...

if what == "common":
#...

#added to _dowork function:

thread1 = self.launch_thread_with_message(self._compare,"Leftside", args=(dir1,dir2,"left"))
thread2 = self.launch_thread_with_message(self._compare,"Rightside", args=(dir1,dir2,"right"))

thread1.join()
thread2.join()

self._dcmp = self._compare(dir1, dir2, "common")

tkhyn avatar Jun 26 '17 11:06 tkhyn

Can you explain what is happening when this code is used: It doesn't feels efficient (Line:258) And a bit later: Line:375

To be 100% honest, as of today, no I can't explain. I'm not even sure I wrote that part! This code comes from an old script I tweaked to my needs, and I never bothered about optimizing it. My only concern was fitness for purpose and a few added features from the original script. If you find more efficient ways to achieve the same end results, I'll be happy to approve your changes if you want to initiate a pull request.

FYI I've added threading for left and right

Great, if all the tests pass with that modification and you don't notice any regression bug you're more than welcome to submit a pull request!

tkhyn avatar Jun 26 '17 12:06 tkhyn