Пример #1
0
    def get_lilypond_version_string():
        '''Gets LilyPond version string.

        ..  container:: example

            >>> abjad_configuration = abjad.AbjadConfiguration()
            >>> abjad_configuration.get_lilypond_version_string() # doctest: +SKIP
            '2.19.1'

        Returns string.
        '''
        from abjad import abjad_configuration
        from abjad.tools import systemtools
        if AbjadConfiguration._lilypond_version_string is not None:
            return AbjadConfiguration._lilypond_version_string
        lilypond = abjad_configuration.get('lilypond_path')
        if not lilypond:
            lilypond = systemtools.IOManager.find_executable('lilypond')
            if lilypond:
                lilypond = lilypond[0]
            else:
                lilypond = 'lilypond'
        command = lilypond + ' --version'
        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
        lilypond_version_string = proc.stdout.readline().decode()
        lilypond_version_string = lilypond_version_string.split(' ')[-1]
        lilypond_version_string = lilypond_version_string.strip()
        AbjadConfiguration._lilypond_version_string = lilypond_version_string
        return lilypond_version_string
Пример #2
0
    def get_lilypond_version_string():
        """
        Gets LilyPond version string.

        ..  container:: example

            >>> abjad_configuration = abjad.AbjadConfiguration()
            >>> abjad_configuration.get_lilypond_version_string()
            '2.19...'

        Returns string.
        """
        from abjad import abjad_configuration
        from abjad import system

        if AbjadConfiguration._lilypond_version_string is not None:
            return AbjadConfiguration._lilypond_version_string
        lilypond = abjad_configuration.get("lilypond_path")
        if not lilypond:
            lilypond = system.IOManager.find_executable("lilypond")
            if lilypond:
                lilypond = lilypond[0]
            else:
                lilypond = "lilypond"
        command = lilypond + " --version"
        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
        lilypond_version_string = proc.stdout.readline().decode()
        lilypond_version_string = lilypond_version_string.split(" ")[-1]
        lilypond_version_string = lilypond_version_string.strip()
        AbjadConfiguration._lilypond_version_string = lilypond_version_string
        return lilypond_version_string
Пример #3
0
    def run_lilypond(
        ly_path: str,
        *,
        flags: str = None,
        lilypond_log_file_path: str = None,
        lilypond_path: str = None,
        ) -> bool:
        """
        Runs LilyPond on ``ly_path``.

        Writes redirected output of Unix ``date`` to top line of LilyPond log
        file.

        Then appends redirected output of LilyPond output to the LilyPond log
        file.
        """
        ly_path = str(ly_path)
        lilypond_path = _configuration.get('lilypond_path')
        if not lilypond_path:
            lilypond_paths = IOManager.find_executable('lilypond')
            if lilypond_paths:
                lilypond_path = lilypond_paths[0]
            else:
                lilypond_path = 'lilypond'
        lilypond_base, extension = os.path.splitext(ly_path)
        flags = flags or ''
        date = datetime.datetime.now().strftime('%c')
        if lilypond_log_file_path is None:
            log_file_path = _configuration.lilypond_log_file_path
        else:
            log_file_path = lilypond_log_file_path
        command = '{} {} -dno-point-and-click -o {} {}'.format(
            lilypond_path,
            flags,
            lilypond_base,
            ly_path,
            )
        process = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            )
        subprocess_output, _ = process.communicate()
        subprocess_output = subprocess_output.decode(errors='ignore')
        exit_code = process.returncode
        with open(log_file_path, 'w') as file_pointer:
            file_pointer.write(date + '\n')
            file_pointer.write(subprocess_output)
        postscript_path = ly_path.replace('.ly', '.ps')
        try:
            os.remove(postscript_path)
        except OSError:
            pass
        # TODO: maybe just 'return exit_code'?
        if exit_code:
            return False
        return True
Пример #4
0
    def run_lilypond(
        ly_path: str,
        *,
        flags: str = None,
        lilypond_log_file_path: str = None,
        lilypond_path: str = None,
    ) -> bool:
        """
        Runs LilyPond on ``ly_path``.

        Writes redirected output of Unix ``date`` to top line of LilyPond log
        file.

        Then appends redirected output of LilyPond output to the LilyPond log
        file.
        """
        ly_path = str(ly_path)
        lilypond_path = _configuration.get("lilypond_path")
        if not lilypond_path:
            lilypond_paths = IOManager.find_executable("lilypond")
            if lilypond_paths:
                lilypond_path = lilypond_paths[0]
            else:
                lilypond_path = "lilypond"
        lilypond_base, extension = os.path.splitext(ly_path)
        flags = flags or ""
        date = datetime.datetime.now().strftime("%c")
        if lilypond_log_file_path is None:
            log_file_path = _configuration.lilypond_log_file_path
        else:
            log_file_path = lilypond_log_file_path
        command = "{} {} -dno-point-and-click -o {} {}".format(
            lilypond_path, flags, lilypond_base, ly_path
        )
        process = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
        )
        subprocess_output, _ = process.communicate()
        subprocess_output = subprocess_output.decode(errors="ignore")
        exit_code = process.returncode
        with open(log_file_path, "w") as file_pointer:
            file_pointer.write(date + "\n")
            file_pointer.write(subprocess_output)
        postscript_path = ly_path.replace(".ly", ".ps")
        try:
            os.remove(postscript_path)
        except OSError:
            pass
        # TODO: maybe just 'return exit_code'?
        if exit_code:
            return False
        return True
Пример #5
0
    def run_lilypond(ly_path, flags=None, lilypond_path=None):
        r'''Runs LilyPond on `ly_path`.

        Writes redirected output of Unix ``date`` to top line of LilyPond log
        file.

        Then appends redirected output of LilyPond output to the LilyPond log
        file.

        Returns none.
        '''
        from abjad import abjad_configuration
        from abjad.tools import systemtools
        lilypond_path = abjad_configuration.get('lilypond_path')
        if not lilypond_path:
            lilypond_path = systemtools.IOManager.find_executable('lilypond')
            if lilypond_path:
                lilypond_path = lilypond_path[0]
            else:
                lilypond_path = 'lilypond'
        lilypond_base, extension = os.path.splitext(ly_path)
        flags = flags or ''
        date = datetime.datetime.now().strftime('%c')
        log_file_path = abjad_configuration.lilypond_log_file_path
        command = '{} {} -dno-point-and-click -o {} {}'.format(
            lilypond_path,
            flags,
            lilypond_base,
            ly_path,
        )
        process = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
        )
        subprocess_output, _ = process.communicate()
        if sys.version_info[0] == 3:
            subprocess_output = subprocess_output.decode('utf-8')
        exit_code = process.returncode
        with open(log_file_path, 'w') as file_pointer:
            file_pointer.write(date + '\n')
            file_pointer.write(subprocess_output)
        postscript_path = ly_path.replace('.ly', '.ps')
        try:
            os.remove(postscript_path)
        except OSError:
            pass
        if exit_code:
            return False
        return True
Пример #6
0
    def run_lilypond(ly_path, flags=None, lilypond_path=None):
        r'''Runs LilyPond on `ly_path`.

        Writes redirected output of Unix ``date`` to top line of LilyPond log
        file.

        Then appends redirected output of LilyPond output to the LilyPond log
        file.

        Returns none.
        '''
        from abjad import abjad_configuration
        from abjad.tools import systemtools
        lilypond_path = abjad_configuration.get('lilypond_path')
        if not lilypond_path:
            lilypond_path = systemtools.IOManager.find_executable('lilypond')
            if lilypond_path:
                lilypond_path = lilypond_path[0]
            else:
                lilypond_path = 'lilypond'
        lilypond_base, extension = os.path.splitext(ly_path)
        flags = flags or ''
        date = datetime.datetime.now().strftime('%c')
        log_file_path = abjad_configuration.lilypond_log_file_path
        command = '{} {} -dno-point-and-click -o {} {}'.format(
            lilypond_path,
            flags,
            lilypond_base,
            ly_path,
            )
        process = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            )
        subprocess_output, _ = process.communicate()
        if sys.version_info[0] == 3:
            subprocess_output = subprocess_output.decode('utf-8')
        exit_code = process.returncode
        with open(log_file_path, 'w') as file_pointer:
            file_pointer.write(date + '\n')
            file_pointer.write(subprocess_output)
        postscript_path = ly_path.replace('.ly', '.ps')
        try:
            os.remove(postscript_path)
        except OSError:
            pass
        if exit_code:
            return False
        return True
Пример #7
0
 def _run_lilypond(self, lilypond_path):
     from abjad import abjad_configuration
     command = '{} -dno-point-and-click -o {} {}'.format(
         abjad_configuration.get('lilypond_path', 'lilypond'),
         str(lilypond_path).replace('.ly', ''),
         str(lilypond_path),
         )
     with systemtools.TemporaryDirectoryChange(str(lilypond_path.parent)):
         exit_code = subprocess.call(command, shell=True)
     if exit_code:
         print('    Failed to render: {!s}'.format(
             lilypond_path.relative_to(self._score_package_path)))
         sys.exit(1)
     return lilypond_path.with_suffix('.pdf')
 def _run_lilypond(self, lilypond_path):
     from abjad import abjad_configuration
     command = '{} -dno-point-and-click -o {} {}'.format(
         abjad_configuration.get('lilypond_path', 'lilypond'),
         str(lilypond_path).replace('.ly', ''),
         str(lilypond_path),
     )
     with systemtools.TemporaryDirectoryChange(str(lilypond_path.parent)):
         exit_code = subprocess.call(command, shell=True)
     if exit_code:
         print('    Failed to render: {!s}'.format(
             lilypond_path.relative_to(self._score_package_path)))
         sys.exit(1)
     return lilypond_path.with_suffix('.pdf')
Пример #9
0
 def _write_lilypond_pdf(
     self,
     ly_path,
     output_directory_path,
     ):
     from abjad import abjad_configuration
     pdf_path = output_directory_path.joinpath('illustration.pdf')
     message = '    Writing {!s} ... '
     message = message.format(pdf_path.relative_to(self._score_repository_path))
     print(message, end='')
     command = '{} -dno-point-and-click -o {} {}'.format(
         abjad_configuration.get('lilypond_path', 'lilypond'),
         str(ly_path).replace('.ly', ''),
         str(ly_path),
         )
     with systemtools.Timer() as timer:
         with systemtools.TemporaryDirectoryChange(str(ly_path.parent)):
             exit_code = subprocess.call(command, shell=True)
     if exit_code:
         print('Failed!')
         sys.exit(1)
     print('OK!')
     self._report_time(timer, prefix='LilyPond runtime')
Пример #10
0
    def get_lilypond_version_string():
        '''Gets LilyPond version string.

        ..  container:: example

            ::

                >>> abjad_configuration.get_lilypond_version_string() # doctest: +SKIP
                '2.19.1'

        Returns string.
        '''
        from abjad import abjad_configuration
        from abjad.tools import systemtools
        if AbjadConfiguration._lilypond_version_string is not None:
            return AbjadConfiguration._lilypond_version_string
        lilypond = abjad_configuration.get('lilypond_path')
        if not lilypond:
            lilypond = systemtools.IOManager.find_executable('lilypond')
            if lilypond:
                lilypond = lilypond[0]
            else:
                lilypond = 'lilypond'
        command = lilypond + ' --version'
        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
        if sys.version_info[0] == 2:
            lilypond_version_string = proc.stdout.readline()
        else:
            import locale
            encoding = locale.getdefaultlocale()[1]
            if encoding is None:
                encoding = 'utf-8'
            lilypond_version_string = proc.stdout.readline().decode(encoding)
        lilypond_version_string = lilypond_version_string.split(' ')[-1]
        lilypond_version_string = lilypond_version_string.strip()
        AbjadConfiguration._lilypond_version_string = lilypond_version_string
        return lilypond_version_string
Пример #11
0
 def _write_lilypond_pdf(
     self,
     ly_path,
     output_directory_path,
 ):
     from abjad import abjad_configuration
     pdf_path = output_directory_path.joinpath('illustration.pdf')
     message = '    Writing {!s} ... '
     message = message.format(
         pdf_path.relative_to(self._score_repository_path))
     print(message, end='')
     command = '{} -dno-point-and-click -o {} {}'.format(
         abjad_configuration.get('lilypond_path', 'lilypond'),
         str(ly_path).replace('.ly', ''),
         str(ly_path),
     )
     with systemtools.Timer() as timer:
         with systemtools.TemporaryDirectoryChange(str(ly_path.parent)):
             exit_code = subprocess.call(command, shell=True)
     if exit_code:
         print('Failed!')
         sys.exit(1)
     print('OK!')
     self._report_time(timer, prefix='LilyPond runtime')