Ejemplo n.º 1
0
    def get_unique_typed_child(self, klass):
        cn = self.get_typed_children(klass)
        if len(cn) <> 1:
            ly.error(self.__dict__)
            raise 'Child is not unique for', (klass, 'found', cn)

        return cn[0]
Ejemplo n.º 2
0
def do_conversion(s, from_version, to_version):
    """Apply conversions from FROM_VERSION to TO_VERSION.  Return
tuple (LAST,LASTCHANGED,STR,ERRORS), with the last applied conversion,
the last conversion resulting in a change, the resulting
string and the number of errors."""
    conv_list = get_conversions(from_version, to_version)

    ly.progress(_("Applying conversion: "), newline=False)

    last_conversion = None
    last_change = None
    errors = 0
    try:
        for x in conv_list:
            if x != conv_list[-1]:
                ly.progress(tup_to_str(x[0]), newline=False)
                ly.progress(', ', newline=False)
            else:
                ly.progress(tup_to_str(x[0]))
            newstr = x[1](s)
            last_conversion = x[0]
            if newstr != s:
                last_change = last_conversion
            s = newstr

    except convertrules.FatalConversionError:
        ly.error(
            _("Error while converting") + '\n' +
            _("Stopping at last successful rule"))
        errors += 1

    return (last_conversion, last_change, s, errors)
Ejemplo n.º 3
0
    def get_unique_typed_child (self, klass):
        cn = self.get_typed_children(klass)
        if len (cn) <> 1:
            ly.error (self.__dict__)
            raise 'Child is not unique for', (klass, 'found', cn)

        return cn[0]
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
def do_conversion (str, from_version, to_version):
    """Apply conversions from FROM_VERSION to TO_VERSION.  Return
tuple (LAST,LASTCHANGED,STR,ERRORS), with the last applied conversion,
the last conversion resulting in a change, the resulting
string and the number of errors."""
    conv_list = get_conversions (from_version, to_version)

    ly.progress (_ ("Applying conversion: "), newline = False)

    last_conversion = None
    last_change = None
    errors = 0
    try:
        for x in conv_list:
            if x != conv_list[-1]:
                ly.progress (tup_to_str (x[0]), newline = False)
                ly.progress (', ', newline = False)
            else:
                ly.progress (tup_to_str (x[0]))
            newstr = x[1] (str)
            last_conversion = x[0]
            if (newstr != str):
                last_change = last_conversion
            str = newstr

    except convertrules.FatalConversionError:
        ly.error (_ ("Error while converting")
                  + '\n'
                  + _ ("Stopping at last successful rule"))
        errors += 1

    return (last_conversion, last_change, str, errors)
Ejemplo n.º 6
0
def do_conversion (str, from_version, to_version):
    """Apply conversions from FROM_VERSION to TO_VERSION.  Return
tuple (LAST,STR), with the last successful conversion and the resulting
string."""
    conv_list = get_conversions (from_version, to_version)

    ly.progress (_ ("Applying conversion: "), newline = False)

    last_conversion = ()
    try:
        if not conv_list:
            last_conversion = to_version
        for x in conv_list:
            if x != conv_list[-1]:
                ly.progress (tup_to_str (x[0]), newline = False)
                ly.progress (', ', newline = False)
            else:
                ly.progress (tup_to_str (x[0]))
            str = x[1] (str)
            last_conversion = x[0]

    except convertrules.FatalConversionError:
        ly.error (_ ("Error while converting")
                  + '\n'
                  + _ ("Stopping at last successful rule"))

    return (last_conversion, str)
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def do_conversion (str, from_version, to_version):
    """Apply conversions from FROM_VERSION to TO_VERSION.  Return
tuple (LAST,STR), with the last successful conversion and the resulting
string."""
    conv_list = get_conversions (from_version, to_version)

    ly.progress (_ ("Applying conversion: "), newline = False)

    last_conversion = None
    errors = 0
    try:
        for x in conv_list:
            if x != conv_list[-1]:
                ly.progress (tup_to_str (x[0]), newline = False)
                ly.progress (', ', newline = False)
            else:
                ly.progress (tup_to_str (x[0]))
            str = x[1] (str)
            last_conversion = x[0]

    except convertrules.FatalConversionError:
        ly.error (_ ("Error while converting")
                  + '\n'
                  + _ ("Stopping at last successful rule"))
        errors += 1

    return (last_conversion, str, errors)
Ejemplo n.º 10
0
    def filter_pipe(self, input: bytes, cmd: str) -> bytes:
        """Pass input through cmd, and return the result.

        Args:
          input: the input
          cmd: a shell command

        Returns:
          the filtered 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()

        # assume stderr always is text
        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:"))
            sys.stderr.write(err)
            exit(status)

        debug('\n')

        return output
Ejemplo n.º 11
0
    def link_all_output_files(self, output_dir, destination):
        existing, missing = self.all_output_files(output_dir)
        if missing:
            ly.error(_('Missing files: %s') % ', '.join(missing))
            raise CompileError(self.basename())
        for name in existing:
            if (self.global_options.use_source_file_names
                    and isinstance(self, LilypondFileSnippet)):
                base, ext = os.path.splitext(name)
                components = base.split('-')
                # ugh, assume filenames with prefix with one dash (lily-xxxx)
                if len(components) > 2:
                    base_suffix = '-' + components[-1]
                else:
                    base_suffix = ''
                final_name = self.final_basename() + base_suffix + ext
            else:
                final_name = name
            try:
                os.unlink(os.path.join(destination, final_name))
            except OSError:
                pass

            src = os.path.join(output_dir, name)
            dst = os.path.join(destination, final_name)
            dst_path = os.path.split(dst)[0]
            os.makedirs(dst_path, exist_ok=True)
            try:
                if (self.global_options.use_source_file_names
                        and isinstance(self, LilypondFileSnippet)):
                    content = open(src, 'rb').read()
                    basename = self.basename().encode('utf-8')
                    final_basename = self.final_basename().encode('utf-8')
                    content = content.replace(basename, final_basename)
                    open(dst, 'wb').write(content)
                else:
                    try:
                        os.link(src, dst)
                    except AttributeError:
                        shutil.copyfile(src, dst)
            except (IOError, OSError):
                ly.error(_('Could not overwrite file %s') % dst)
                raise CompileError(self.basename())
Ejemplo n.º 12
0
def main ():
    files = do_options ()

    # should parse files[] to read \version?
    if global_options.show_rules:
        show_rules (sys.stdout, global_options.from_version, global_options.to_version)
        sys.exit (0)

    identify ()

    for f in files:
        if f == '-':
            f = ''
        elif not os.path.isfile (f):
            ly.error (_ ("%s: Unable to open file") % f)
            if len (files) == 1:
                sys.exit (1)
            continue
        try:
            do_one_file (f)
        except UnknownVersion:
            ly.error (_ ("%s: Unable to determine version.  Skipping") % f)
        except InvalidVersion:
            # Compat code for 2.x and 3.0 syntax ("except .. as v" doesn't 
            # work in python 2.4!):
            t, v, b = sys.exc_info ()
            ly.error (_ ("%s: Invalid version string `%s' \n"
                         "Valid version strings consist of three numbers, "
                         "separated by dots, e.g. `2.8.12'") % (f, v.version) )
Ejemplo n.º 13
0
def main():
    files = do_options()

    # should parse files[] to read \version?
    if global_options.show_rules:
        show_rules(sys.stdout, global_options.from_version,
                   global_options.to_version)
        sys.exit(0)

    identify()

    errors = 0
    for f in files:
        if f == '-':
            f = ''
        elif not os.path.isfile(f):
            ly.error(_("%s: Unable to open file") % f)
            errors += 1
            continue
        try:
            errors += do_one_file(f)
        except UnknownVersion:
            ly.error(_("%s: Unable to determine version.  Skipping") % f)
            errors += 1
        except InvalidVersion as v:
            ly.error(_("%s: Invalid version string `%s' \n"
                       "Valid version strings consist of three numbers, "
                       "separated by dots, e.g. `2.8.12'") % (f, v.version))
            errors += 1

    if errors:
        ly.warning(gettext.ngettext("There was %d error.",
                                    "There were %d errors.", errors) % errors)
        sys.exit(1)
Ejemplo n.º 14
0
def main():
    files = do_options()

    # should parse files[] to read \version?
    if global_options.show_rules:
        show_rules(sys.stdout, global_options.from_version, global_options.to_version)
        sys.exit(0)

    identify()

    errors = 0
    for f in files:
        f = f.decode(sys.stdin.encoding or "utf-8")
        if f == "-":
            f = ""
        elif not os.path.isfile(f):
            ly.error(_(u"%s: Unable to open file") % f)
            errors += 1
            continue
        try:
            errors += do_one_file(f)
        except UnknownVersion:
            ly.error(_(u"%s: Unable to determine version.  Skipping") % f)
            errors += 1
        except InvalidVersion:
            # Compat code for 2.x and 3.0 syntax ("except .. as v" doesn't
            # work in python 2.4!):
            t, v, b = sys.exc_info()
            ly.error(
                _(
                    u"%s: Invalid version string `%s' \n"
                    "Valid version strings consist of three numbers, "
                    "separated by dots, e.g. `2.8.12'"
                )
                % (f, v.version)
            )
            errors += 1

    if errors:
        ly.warning(ly.ungettext("There was %d error.", "There were %d errors.", errors) % errors)
        sys.exit(1)
Ejemplo n.º 15
0
def main():
    files = do_options()

    # should parse files[] to read \version?
    if global_options.show_rules:
        show_rules(sys.stdout, global_options.from_version,
                   global_options.to_version)
        sys.exit(0)

    identify()

    errors = 0
    for f in files:
        f = f.decode(sys.stdin.encoding or "utf-8")
        if f == '-':
            f = ''
        elif not os.path.isfile(f):
            ly.error(_(u"%s: Unable to open file") % f)
            errors += 1
            continue
        try:
            errors += do_one_file(f)
        except UnknownVersion:
            ly.error(_(u"%s: Unable to determine version.  Skipping") % f)
            errors += 1
        except InvalidVersion:
            # Compat code for 2.x and 3.0 syntax ("except .. as v" doesn't
            # work in python 2.4!):
            t, v, b = sys.exc_info()
            ly.error(
                _(u"%s: Invalid version string `%s' \n"
                  "Valid version strings consist of three numbers, "
                  "separated by dots, e.g. `2.8.12'") % (f, v.version))
            errors += 1

    if errors:
        ly.warning(
            ly.ungettext("There was %d error.", "There were %d errors.",
                         errors) % errors)
        sys.exit(1)
Ejemplo n.º 16
0
def dump_voice(thread, skip):
    global reference_note, time
    ref = Note(0, 4*12, 0)
    if not reference_note:
        reference_note = ref
    else:
        ref.duration = reference_note.duration
        reference_note = ref
    last_e = None
    chs = []
    ch = []

    for e in thread:
        if last_e and last_e[0] == e[0]:
            ch.append(e[1])
        else:
            if ch:
                chs.append((last_e[0], ch))

            ch = [e[1]]

        last_e = e

    if ch:
        chs.append((last_e[0], ch))
    t = 0
    last_t = 0
    last_bar_t = 0
    bar_count = 1

    lines = ['']
    for ch in chs:
        t = ch[0]

        i = lines[-1].rfind('\n') + 1
        if len(lines[-1][i:]) > LINE_BELL:
            lines.append('')

        if t - last_t > 0:
            d = t - last_t
            if bar_max and t > time.bar_clocks() * bar_max:
                d = time.bar_clocks() * bar_max - last_t
            lines[-1] = lines[-1] + dump_skip(skip, d)
        elif t - last_t < 0:
            ly.error('BUG: time skew')

        (s, last_bar_t, bar_count) = dump_bar_line(last_bar_t,
                                                   t, bar_count)

        if bar_max and bar_count > bar_max:
            break

        lines[-1] = lines[-1] + s
        lines[-1] = lines[-1] + dump_chord(ch[1])

        clocks = 0
        for i in ch[1]:
            if i.clocks > clocks:
                clocks = i.clocks

        last_t = t + clocks

        (s, last_bar_t, bar_count) = dump_bar_line(last_bar_t,
                                                   last_t, bar_count)
        lines[-1] = lines[-1] + s

    return '\n  '.join(lines) + '\n'