コード例 #1
0
ファイル: publish.py プロジェクト: Aliminator666/calibre
    def run(self, opts):
        from setup.multitail import pipe, multitail
        for x in glob.glob(os.path.join(self.d(self.SRC), 'dist', '*')):
            os.remove(x)
        build = os.path.join(self.d(self.SRC), 'build')
        if os.path.exists(build):
            shutil.rmtree(build)
        processes = []
        tdir = tempfile.mkdtemp('_build_logs')
        atexit.register(shutil.rmtree, tdir)
        self.info('Starting builds for all platforms, this will take a while...')
        def kill_child_on_parent_death():
            import ctypes, signal
            libc = ctypes.CDLL("libc.so.6")
            libc.prctl(1, signal.SIGTERM)

        for x in ('linux', 'osx', 'win'):
            r, w = pipe()
            p = subprocess.Popen([sys.executable, 'setup.py', x], stdout=w, stderr=subprocess.STDOUT,
                                 cwd=self.d(self.SRC), preexec_fn=kill_child_on_parent_death)
            p.log, p.start_time, p.bname = r, time.time(), x
            p.save = open(os.path.join(tdir, x), 'w+b')
            p.duration = None
            processes.append(p)

        def workers_running():
            running = False
            for p in processes:
                rc = p.poll()
                if rc is not None:
                    if p.duration is None:
                        p.duration = int(time.time() - p.start_time)
                else:
                    running = True
            return running

        stop_multitail = multitail(
            [proc.log for proc in processes],
            name_map={proc.log:proc.bname for proc in processes},
            copy_to=[proc.save for proc in processes]
        )[0]

        while workers_running():
            os.waitpid(-1, 0)

        stop_multitail()

        failed = False
        for p in processes:
            if p.poll() != 0:
                failed = True
                log = p.save
                log.flush()
                log.seek(0)
                raw = log.read()
                self.info('Building of %s failed' % p.bname)
                sys.stderr.write(raw)
                sys.stderr.write(b'\n\n')
        if failed:
            raise SystemExit('Building of installers failed!')

        for p in sorted(processes, key=lambda p:p.duration):
            self.info('Built %s in %d minutes and %d seconds' % (p.bname, p.duration // 60, p.duration % 60))

        for installer in installers(include_source=False):
            if not os.path.exists(self.j(self.d(self.SRC), installer)):
                raise SystemExit('The installer %s does not exist' % os.path.basename(installer))
コード例 #2
0
    def run(self, opts):
        from setup.multitail import pipe, multitail
        for x in glob.glob(os.path.join(self.d(self.SRC), 'dist', '*')):
            os.remove(x)
        build = os.path.join(self.d(self.SRC), 'build')
        if os.path.exists(build):
            shutil.rmtree(build)
        processes = []
        tdir = tempfile.mkdtemp('_build_logs')
        atexit.register(shutil.rmtree, tdir)
        self.info(
            'Starting builds for all platforms, this will take a while...')

        def kill_child_on_parent_death():
            import ctypes, signal
            libc = ctypes.CDLL("libc.so.6")
            libc.prctl(1, signal.SIGTERM)

        for x in ('linux', 'osx', 'win'):
            r, w = pipe()
            p = subprocess.Popen([sys.executable, 'setup.py', x],
                                 stdout=w,
                                 stderr=subprocess.STDOUT,
                                 cwd=self.d(self.SRC),
                                 preexec_fn=kill_child_on_parent_death)
            p.log, p.start_time, p.bname = r, time.time(), x
            p.save = open(os.path.join(tdir, x), 'w+b')
            p.duration = None
            processes.append(p)

        def workers_running():
            running = False
            for p in processes:
                rc = p.poll()
                if rc is not None:
                    if p.duration is None:
                        p.duration = int(time.time() - p.start_time)
                else:
                    running = True
            return running

        stop_multitail = multitail(
            [proc.log for proc in processes],
            name_map={proc.log: proc.bname
                      for proc in processes},
            copy_to=[proc.save for proc in processes])[0]

        while workers_running():
            os.waitpid(-1, 0)

        stop_multitail()

        failed = False
        for p in processes:
            if p.poll() != 0:
                failed = True
                log = p.save
                log.flush()
                log.seek(0)
                raw = log.read()
                self.info('Building of %s failed' % p.bname)
                sys.stderr.write(raw)
                sys.stderr.write(b'\n\n')
        if failed:
            raise SystemExit('Building of installers failed!')

        for p in sorted(processes, key=lambda p: p.duration):
            self.info('Built %s in %d minutes and %d seconds' %
                      (p.bname, p.duration // 60, p.duration % 60))

        for installer in installers(include_source=False):
            if not os.path.exists(self.j(self.d(self.SRC), installer)):
                raise SystemExit('The installer %s does not exist' %
                                 os.path.basename(installer))