Exemplo n.º 1
0
Arquivo: c.py Projeto: crei0/toolbelt
def find_includes(filename):
    includes = []
    if filename:
        parent = os.path.dirname(filename)
        if not parent:
            return includes

        includes.append('-I' + parent)
        inc = find(parent, 'include')
        if inc:
            includes.append('-I' + inc)

    return includes
Exemplo n.º 2
0
    def run(self, cmd, code):
        project = find(os.path.dirname(self.filename), '.project', True)
        if not project:
            return

        filename = self.filename.replace(project, '', 1).lstrip(os.sep)
        project = os.path.basename(project)

        # can't stdin or temp use file - hack time?
        # this *could* become a tmp directory
        # but I'd need to know all files to copy
        # from the source project
        tmp = tempfile.mktemp()
        os.rename(self.filename, tmp)
        # at least we get some inode protection on posix
        inode = None

        with open(self.filename, 'wb') as f:
            f.write(code)
            if os.name == 'posix':
                inode = os.stat(self.filename).st_ino

        try:
            cmd = cmd + ('-p', project, '-f', filename, '-v')
            output = self.communicate(cmd, '')
        finally:
            if inode is not None:
                new_inode = os.stat(self.filename).st_ino
                if new_inode != inode:
                    # they saved over our tmp file, bail
                    return output

            os.unlink(self.filename)
            os.rename(tmp, self.filename)

        return output