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

Code explanation... #13

Open
tkhyn opened this issue Jun 26, 2017 · 1 comment
Open

Code explanation... #13

tkhyn opened this issue Jun 26, 2017 · 1 comment
Labels
enhancement New feature or request minor

Comments

@tkhyn
Copy link
Owner

tkhyn commented Jun 26, 2017

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
Copy link
Owner Author

tkhyn commented Jun 26, 2017

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 tkhyn added minor enhancement New feature or request labels Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

No branches or pull requests

1 participant