]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - setuptools_darcs-1.2.12.egg/setuptools_darcs/setuptools_darcs.py
627265facef40bda5c9dc7c2131fd9afc6b5c0ff
[tahoe-lafs/tahoe-lafs.git] / setuptools_darcs-1.2.12.egg / setuptools_darcs / setuptools_darcs.py
1 import os, re
2
3 from subprocess import Popen, PIPE
4
5 THISDIR_RE=re.compile("What's new in \"(.*)\"")
6
7 def exec_darcs(darcscmd):
8     cmd = ['darcs'] + darcscmd
9     try:
10         p = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
11     except EnvironmentError:
12         cmd = ['realdarcs.exe'] + darcscmd
13         p = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
14         
15     output = p.communicate()[0]
16     return (p.returncode, output)
17
18 def run_darcs_query_manifest():
19     return exec_darcs(['query', 'manifest'])
20
21 def run_darcs_whatsnew_dot():
22     return exec_darcs(['whatsnew', '.'])
23
24 def find_files_for_darcs(dirname):
25     try:
26         unused, whatsnewoutput = run_darcs_whatsnew_dot()
27         queryretcode, queryoutput = run_darcs_query_manifest()
28     except EnvironmentError:
29         if not os.path.exists('PKG-INFO'):
30             from distutils import log
31             log.info("Unable to execute darcs -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files.  If you are not building a package then you can ignore this warning.")
32         # Oh well -- just return None.
33         return
34
35     if queryretcode != 0:
36         if not os.path.exists('PKG-INFO'):
37             from distutils import log
38             log.warn("Failure to get the list of managed files from darcs -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files.  If you are not building a package then you can ignore this warning.")
39         # Oh well -- just return None.
40         return
41
42     # We got output.
43     mo = THISDIR_RE.search(whatsnewoutput)
44     if mo:
45         curdirname = mo.group(1)
46         while curdirname.endswith('/'):
47             curdirname = curdirname[:-1]
48         curdirname += "/"
49     else:
50         curdirname = ""
51
52     # Prepend this directory.
53     rel_to_repo_dirname = curdirname + dirname
54
55     # Normalize rel_to_repo_dirname from local form to the form that setuptools uses to the form that "darcs query manifest" outputs (unix form).
56     rel_to_repo_dirname = rel_to_repo_dirname.replace('\\', '/')
57     while rel_to_repo_dirname.endswith('/'):
58         rel_to_repo_dirname = rel_to_repo_dirname[:-1]
59
60     # Append a '/' to make sure we don't match "foobar" when rel_to_repo_dirname is "foo".
61     if rel_to_repo_dirname:
62         rel_to_repo_dirname += '/'
63
64     warn = True
65     for fn in queryoutput.split('\n'):
66         if fn == ".":
67             continue
68         if fn.startswith('./'):
69             fn = fn[2:]
70         if fn.startswith(rel_to_repo_dirname):
71             fn = fn[len(rel_to_repo_dirname):]
72             warn = False
73             # We need to replace "/" by "\\" because setuptools can't includes web/*.xhtml files on Windows, due of path separator
74             # This correct ticket #1033
75             yield fn.replace('/', os.sep)
76
77     if warn and not os.path.exists('PKG-INFO'):
78         from distutils import log
79         log.warn("Didn't find any files in directory \"%s\" (full path: \"%s\") that were managed by darcs revision control -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files.  If you are not building a package then you can ignore this warning." % (dirname, os.path.abspath(rel_to_repo_dirname),))