Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>first, eliminate useless statement</p> <pre><code># check if correct file extension def checkExt(path): return path.endswith(FILE_EXT) </code></pre> <p>then be a little more pythonic</p> <pre><code># rsync subprocess def rsyncFile(path): printLog("Syncing file '%s'" % os.path.basename(path)) try: p = subprocess.Popen(['rsync', '-a', '--remove-source-files', path, REM_DIR], stdout=subprocess.PIPE) for line in p.stdout: printLog("rsync: '%s'" %line) p.wait() printlog( { 0 : '&lt;&lt;&lt; File synced successfully :) &gt;&gt;&gt;', 10 : '****** Please check your internet connection!! ****** Rsync error code: %s' % p.returncode, }.get(p.returncode, '****** Please check your internet connection!! ****** Rsync error code: %s' % p.returncode) # A switch statement in python ! ) except: logging.exception("An exception occured") </code></pre> <p>When using "logging.exception" you will display the exception and traceback that caused the problem.</p> <p>then reduce main</p> <pre><code>def main(): while True: files = [f for f in getFiles(LOC_DIR) if checkExt(f)] if len(files) == 1: printLog('&lt;&lt;&lt; Found %s matching file &gt;&gt;&gt;' % len(files)) elif len(files) &gt; 1: printLog('&lt;&lt;&lt; Found %s matching files &gt;&gt;&gt;' % len(files)) for f in files: if checkSize(f): rsyncFile(f) printLog('No files found. Checking again in %s seconds' % RUN_INT) time.sleep(RUN_INT) printLog('Checking for files') </code></pre> <p>the "while True:" statement will avoid recursion limit you could easily reach when calling main() at the end of the main code</p> <p>comments and remarks are welcome :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload