コード例 #1
0
ファイル: book_snippets.py プロジェクト: sightreader/lilypond
    def filter_pipe (self, input, cmd):
        """Pass input through cmd, and return the result."""

        debug (_ ("Running through filter `%s'") % cmd, True)

        closefds = True
        if (sys.platform == "mingw32"):
            closefds = False
        p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=closefds)
        (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
        stdin.write (input)
        status = stdin.close ()

        if not status:
            status = 0
            output = stdout.read ()
            status = stdout.close ()
            err = stderr.read ().decode ('utf-8')

        if not status:
            status = 0
        signal = 0x0f & status
        if status or (not output and err):
            exit_status = status >> 8
            ly.error (_ ("`%s' failed (%d)") % (cmd, exit_status))
            ly.error (_ ("The error log is as follows:"))
            ly.stderr_write (err)
            ly.stderr_write (stderr.read ().decode ('utf-8'))
            exit (status)

        debug ('\n')

        return output
コード例 #2
0
    def filter_pipe (self, input, cmd):
        """Pass input through cmd, and return the result."""

        debug (_ ("Running through filter `%s'") % cmd, True)

        # TODO: Use Popen once we resolve the problem with msvcrt in Windows:
        (stdin, stdout, stderr) = os.popen3 (cmd)
        # p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
        # (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
        stdin.write (input)
        status = stdin.close ()

        if not status:
            status = 0
            output = stdout.read ()
            status = stdout.close ()
            err = stderr.read ()

        if not status:
            status = 0
        signal = 0x0f & status
        if status or (not output and err):
            exit_status = status >> 8
            ly.error (_ ("`%s' failed (%d)") % (cmd, exit_status))
            ly.error (_ ("The error log is as follows:"))
            ly.stderr_write (err)
            ly.stderr_write (stderr.read ())
            exit (status)

        debug ('\n')

        return output
コード例 #3
0
ファイル: book_snippets.py プロジェクト: Keith-OHara/lilypond
    def filter_pipe (self, input, cmd):
        """Pass input through cmd, and return the result."""

        debug (_ ("Running through filter `%s'") % cmd, True)

        closefds = True
        if (sys.platform == "mingw32"):
            closefds = False
        p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=closefds)
        (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
        stdin.write (input)
        status = stdin.close ()

        if not status:
            status = 0
            output = stdout.read ()
            status = stdout.close ()
            err = stderr.read ()

        if not status:
            status = 0
        signal = 0x0f & status
        if status or (not output and err):
            exit_status = status >> 8
            ly.error (_ ("`%s' failed (%d)") % (cmd, exit_status))
            ly.error (_ ("The error log is as follows:"))
            ly.stderr_write (err)
            ly.stderr_write (stderr.read ())
            exit (status)

        debug ('\n')

        return output
コード例 #4
0
ファイル: musicxml.py プロジェクト: angeleyes/lilypond
    def message(self, msg):
        ly.stderr_write(msg + "\n")

        p = self
        while p:
            sys.stderr.write(
                "  In: <%s %s>\n" % (p._name, " ".join(["%s=%s" % item for item in p._attribute_dict.items()]))
            )
            p = p.get_parent()
コード例 #5
0
ファイル: convert-ly.py プロジェクト: angeleyes/lilypond
def do_one_file (infile_name):
    ly.stderr_write (_ ("Processing `%s\'... ") % infile_name)
    sys.stderr.write ('\n')

    if infile_name:
        infile = open (infile_name, 'r')
        input = infile.read ()
        infile.close ()
    else:
        input = sys.stdin.read ()

    from_version = None
    to_version = None
    if global_options.from_version:
        from_version = global_options.from_version
    else:
        guess = guess_lilypond_version (input)
        if not guess:
            raise UnknownVersion ()
        from_version = str_to_tuple (guess)

    if global_options.to_version:
        to_version = global_options.to_version
    else:
        to_version = latest_version ()


    (last, result) = do_conversion (input, from_version, to_version)

    if last:
        if global_options.force_current_version and last == to_version:
            last = str_to_tuple (program_version)

        newversion = r'\version "%s"' % tup_to_str (last)
        if lilypond_version_re.search (result):
            result = re.sub (lilypond_version_re_str,
                     '\\' + newversion, result)
        elif not global_options.skip_version_add:
            result = newversion + '\n' + result
            
        error_file_write ('\n')            
    
        if global_options.edit:
            try:
                os.remove(infile_name + '~')
            except:
                pass
            os.rename (infile_name, infile_name + '~')
            outfile = open (infile_name, 'w')
        else:
            outfile = sys.stdout


        outfile.write (result)

    sys.stderr.flush ()
コード例 #6
0
ファイル: musicxml.py プロジェクト: angeleyes/lilypond
    def get_instrument(self, id):
        if not self._id_instrument_name_dict:
            self.generate_id_instrument_dict()

        instrument_name = self._id_instrument_name_dict.get(id)
        if instrument_name:
            return instrument_name
        else:
            ly.stderr_write(_("Unable to find instrument for ID=%s\n") % id)
            return "Grand Piano"
コード例 #7
0
ファイル: midi2ly.py プロジェクト: bensonby/lilypond
def do_options():
    opt_parser = get_option_parser()
    (options, args) = opt_parser.parse_args()

    if options.warranty:
        warranty()
        sys.exit(0)

    if not args or args[0] == '-':
        opt_parser.print_help()
        ly.stderr_write('\n%s: %s %s\n' %
                        (program_name, _('error: '),
                         _('no files specified on command line.')))
        sys.exit(2)

    if options.duration_quant:
        options.duration_quant = int(options.duration_quant)

    if options.key:
        (alterations, minor) = list(map(int,
                                        (options.key + ':0').split(':')))[0:2]
        sharps = 0
        flats = 0
        if alterations >= 0:
            sharps = alterations
        else:
            flats = -alterations
        options.key = Key(sharps, flats, minor)

    if options.start_quant:
        options.start_quant = int(options.start_quant)

    global bar_max
    if options.preview:
        bar_max = 4

    options.allowed_tuplets = [
        list(map(int,
                 a.replace('/', '*').split('*')))
        for a in options.allowed_tuplets
    ]

    if options.verbose:
        sys.stderr.write('Allowed tuplets: %s\n' %
                         repr(options.allowed_tuplets))

    global global_options
    global_options = options

    return args
コード例 #8
0
ファイル: book_snippets.py プロジェクト: Keith-OHara/lilypond
    def write_ly (self):
        base = self.basename ()
        path = os.path.join (self.global_options.lily_output_dir, base)
        directory = os.path.split(path)[0]
        if not os.path.isdir (directory):
            os.makedirs (directory)
        filename = path + '.ly'
        if os.path.exists (filename):
            existing = open (filename, 'r').read ()

            if self.relevant_contents (existing) != self.relevant_contents (self.full_ly ()):
                warning ("%s: duplicate filename but different contents of original file,\n\
printing diff against existing file." % filename)
                ly.stderr_write (self.filter_pipe (self.full_ly (), 'diff -u %s -' % filename))
        else:
            out = file (filename, 'w')
            out.write (self.full_ly ())
            file (path + '.txt', 'w').write ('image of music')
コード例 #9
0
    def write_ly (self):
        base = self.basename ()
        path = os.path.join (self.global_options.lily_output_dir, base)
        directory = os.path.split(path)[0]
        if not os.path.isdir (directory):
            os.makedirs (directory)
        filename = path + '.ly'
        if os.path.exists (filename):
            existing = open (filename, 'r').read ()

            if self.relevant_contents (existing) != self.relevant_contents (self.full_ly ()):
                warning ("%s: duplicate filename but different contents of original file,\n\
printing diff against existing file." % filename)
                ly.stderr_write (self.filter_pipe (self.full_ly (), 'diff -u %s -' % filename))
        else:
            out = file (filename, 'w')
            out.write (self.full_ly ())
            file (path + '.txt', 'w').write ('image of music')
コード例 #10
0
ファイル: midi2ly.py プロジェクト: emacsmirror/lilypond
def do_options ():
    opt_parser = get_option_parser ()
    (options, args) = opt_parser.parse_args ()

    if options.warranty:
        warranty ()
        sys.exit (0)

    if not args or args[0] == '-':
        opt_parser.print_help ()
        ly.stderr_write ('\n%s: %s %s\n' % (program_name, _ ('error: '),
                         _ ('no files specified on command line.')))
        sys.exit (2)

    if options.duration_quant:
        options.duration_quant = int (options.duration_quant)

    if options.key:
        (alterations, minor) = map (int, (options.key + ':0').split (':'))[0:2]
        sharps = 0
        flats = 0
        if alterations >= 0:
            sharps = alterations
        else:
            flats = - alterations
        options.key = Key (sharps, flats, minor)

    if options.start_quant:
        options.start_quant = int (options.start_quant)

    global bar_max
    if options.preview:
        bar_max = 4

    options.allowed_tuplets = [map (int, a.replace ('/','*').split ('*'))
                for a in options.allowed_tuplets]

    if options.verbose:
        sys.stderr.write ('Allowed tuplets: %s\n' % `options.allowed_tuplets`)

    global global_options
    global_options = options

    return args
コード例 #11
0
    def write_ly(self):
        base = self.basename()
        path = os.path.join(self.global_options.lily_output_dir, base)
        directory = os.path.split(path)[0]
        if not os.path.isdir(directory):
            os.makedirs(directory)

        # First write the XML to a file (so we can link it!)
        if self.compressed:
            xmlfilename = path + '.mxl'
        else:
            xmlfilename = path + '.xml'
        if os.path.exists(xmlfilename):
            diff_against_existing = self.filter_pipe(
                self.contents, 'diff -u %s - ' % xmlfilename)
            if diff_against_existing:
                warning(
                    _("%s: duplicate filename but different contents of original file,\n\
printing diff against existing file.") % xmlfilename)
                ly.stderr_write(diff_against_existing.decode('utf-8'))
        else:
            out = open(xmlfilename, 'wb')
            out.write(self.contents)
            out.close()

        # also write the converted lilypond
        filename = path + '.ly'
        if os.path.exists(filename):
            encoded = self.full_ly().encode('utf-8')
            cmd = 'diff -u %s -' % filename
            diff_against_existing = self.filter_pipe(encoded,
                                                     cmd).decode('utf-8')
            if diff_against_existing:
                warning(
                    _("%s: duplicate filename but different contents of converted lilypond file,\n\
printing diff against existing file.") % filename)
                ly.stderr_write(diff_against_existing.decode('utf-8'))
        else:
            out = codecs.open(filename, 'w', 'utf-8')
            out.write(self.full_ly())
            out.close()
            open(path + '.txt', 'w').write('image of music')
コード例 #12
0
ファイル: book_snippets.py プロジェクト: Keith-OHara/lilypond
    def write_ly (self):
        base = self.basename ()
        path = os.path.join (self.global_options.lily_output_dir, base)
        directory = os.path.split(path)[0]
        if not os.path.isdir (directory):
            os.makedirs (directory)

        # First write the XML to a file (so we can link it!)
        if self.compressed:
            xmlfilename = path + '.mxl'
        else:
            xmlfilename = path + '.xml'
        if os.path.exists (xmlfilename):
            diff_against_existing = self.filter_pipe (self.contents, 'diff -u %s - ' % xmlfilename)
            if diff_against_existing:
                warning (_ ("%s: duplicate filename but different contents of original file,\n\
printing diff against existing file.") % xmlfilename)
                ly.stderr_write (diff_against_existing)
        else:
            out = file (xmlfilename, 'w')
            out.write (self.contents)
            out.close ()

        # also write the converted lilypond
        filename = path + '.ly'
        if os.path.exists (filename):
            diff_against_existing = self.filter_pipe (self.full_ly (), 'diff -u %s -' % filename)
            if diff_against_existing:
                warning (_ ("%s: duplicate filename but different contents of converted lilypond file,\n\
printing diff against existing file.") % filename)
                ly.stderr_write (diff_against_existing)
        else:
            out = file (filename, 'w')
            out.write (self.full_ly ())
            out.close ()
            file (path + '.txt', 'w').write ('image of music')
コード例 #13
0
ファイル: convert-ly.py プロジェクト: angeleyes/lilypond
def error (s):
    ly.stderr_write (program_name + ": " + _ ("error: %s") % s + '\n')
コード例 #14
0
ファイル: convert-ly.py プロジェクト: angeleyes/lilypond
def warning (s):
    ly.stderr_write (program_name + ": " + _ ("warning: %s") % s + '\n')
コード例 #15
0
ファイル: musicxml.py プロジェクト: angeleyes/lilypond
def error(str):
    ly.stderr_write((_("error: %s") % str) + "\n")