Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <a href="http://docs.python.org/2/library/os.html#os.walk" rel="nofollow"><code>os.walk()</code></a> to generate a list of files in either directory (with paths relative to their roots):</p> <pre><code>import os def relative_files(path): """Generate filenames with pathnames relative to the initial path.""" for root, dirnames, files in os.walk(path): relroot = os.path.relpath(root, path) for filename in files: yield os.path.join(relroot, filename) </code></pre> <p>Create a set of paths from one:</p> <pre><code>root_one = 'so.1.0' # use an absolute path here root_two = 'so.1.1' # use an absolute path here files_one = set(relative_files(root_one)) </code></pre> <p>then find all the pathnames in the other root that are the same by using a set intersection:</p> <pre><code>from itertools import izip_longest def different_files(root_one, root_two): """Yield files that differ between the two roots Generate pathnames relative to root_one and root_two that are present in both but have different contents. """ files_one = set(relative_files(root_one)) for same in files_one.intersection(relative_files(root_two)): # same is a relative path, so same file in different roots with open(os.path.join(root_one, same)) as f1, open(os.path.join(root_two, same)) as f2: if any(line1 != line2 for line1, line2 in izip_longest(f1, f2)): # lines don't match, so files don't match! yield same </code></pre> <p><a href="http://docs.python.org/2/library/itertools.html#itertools.izip_longest" rel="nofollow"><code>itertools.izip_longest()</code></a> loops over the files efficiently pairing up lines; if one file is longer than the other the remaining lines will be paired up with <code>None</code> to ensure that you detect one as different from the other.</p> <p>Demo:</p> <pre><code>$ mkdir -p /tmp/so.1.0/p/q $ mkdir -p /tmp/so.1.1/p/q $ echo 'file one' &gt; /tmp/so.1.0/p/q/search.c $ echo 'file two' &gt; /tmp/so.1.1/p/q/search.c $ echo 'file three' &gt; /tmp/so.1.1/p/q/ignored.c $ echo 'matching' &gt; /tmp/so.1.0/p/q/same.c $ echo 'matching' &gt; /tmp/so.1.1/p/q/same.c &gt;&gt;&gt; for different in different_files('/tmp/so.1.0', '/tmp/so.1.1'): ... print different ... p/q/search.c </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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