Exemplo n.º 1
0
def presetup(app_defaults_filename, system_filename, user_filename):
    if not os.path.exists(filesystem.app_data()):
        os.makedirs(filesystem.app_data())
    if not os.path.exists(filesystem.user_data()):
        os.makedirs(filesystem.user_data())
    try:
        cfg.initialise(app_defaults_filename, system_filename, user_filename)
    except UnicodeDecodeError:
        traceback.print_exc()
        print(file=sys.stderr)
        print("\n".join(
            textwrap.wrap(
                "Your %s file is not properly utf8 encoded. Most likely"
                " it is the path to some external program that contain non-ascii"
                " characters. Please edit or delete the file. Or email it to"
                " [email protected], and he will tell you what the problem is." %
                filesystem.rcfile().encode("ascii", "backslashreplace"))),
              file=sys.stderr)
        print(file=sys.stderr)
        sys.exit("I give up (solfege.py)")
    except cfg.CfgParseException as e:
        i18n.setup(".")
        a, b = os.path.split(user_filename)
        renamed_fn = os.path.join(a, "BAD-" + b)
        m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL,
                              Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE,
                              _("Parsing %s failed") % filesystem.rcfile())
        m.format_secondary_text(
            str(e) + "\n\n" +
            _("We cannot recover from this, we can rename the corrupt file to %s and then start the program."
              % renamed_fn))
        m.add_buttons("Rename", 10)
        m.add_buttons(Gtk.STOCK_QUIT, 11)
        m.set_default_response(11)
        ret = m.run()
        if ret == 10:
            os.rename(user_filename, renamed_fn)
            m.destroy()
            cfg.initialise(app_defaults_filename, system_filename,
                           user_filename)
        else:
            sys.exit(1)
    # MIGRATION from 2.9.2 to 2.9.3
    if cfg.get_string("app/lc_messages") == 'C (english)':
        cfg.set_string("app/lc_messages", "C")
Exemplo n.º 2
0
def presetup(app_defaults_filename, system_filename, user_filename):
    if not os.path.exists(filesystem.app_data()):
        os.makedirs(filesystem.app_data())
    if not os.path.exists(filesystem.user_data()):
        os.makedirs(filesystem.user_data())
    try:
        cfg.initialise(app_defaults_filename, system_filename, user_filename)
    except UnicodeDecodeError:
        traceback.print_exc()
        print(file=sys.stderr)
        print("\n".join(textwrap.wrap(
              "Your %s file is not properly utf8 encoded. Most likely"
              " it is the path to some external program that contain non-ascii"
              " characters. Please edit or delete the file. Or email it to"
              " [email protected], and he will tell you what the problem is." % filesystem.rcfile().encode("ascii", "backslashreplace"))), file=sys.stderr)
        print(file=sys.stderr)
        sys.exit("I give up (solfege.py)")
    except cfg.CfgParseException as e:
        i18n.setup(".")
        a, b = os.path.split(user_filename)
        renamed_fn = os.path.join(a, "BAD-" + b)
        m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                Gtk.ButtonsType.NONE,
                _("Parsing %s failed") % filesystem.rcfile())
        m.format_secondary_text(str(e) + "\n\n" + _("We cannot recover from this, we can rename the corrupt file to %s and then start the program." % renamed_fn))
        m.add_buttons("Rename", 10)
        m.add_buttons(Gtk.STOCK_QUIT, 11)
        m.set_default_response(11)
        ret = m.run()
        if ret == 10:
            os.rename(user_filename, renamed_fn)
            m.destroy()
            cfg.initialise(app_defaults_filename, system_filename, user_filename)
        else:
            sys.exit(1)
    # MIGRATION from 2.9.2 to 2.9.3
    if cfg.get_string("app/lc_messages") == 'C (english)':
        cfg.set_string("app/lc_messages", "C")
Exemplo n.º 3
0
if sys.platform == 'win32':
    # Migration added in solfege 3.9.0.
    try:
        if not os.path.exists(filesystem.app_data()):
            if os.path.exists(
                    os.path.join(filesystem.get_home_dir(), ".solfege")):
                shutil.copytree(
                    os.path.join(filesystem.get_home_dir(), ".solfege"),
                    filesystem.app_data())
            else:
                os.mkdir(filesystem.app_data())
        if not os.path.exists(filesystem.rcfile()):
            if os.path.exists(
                    os.path.join(filesystem.get_home_dir(), ".solfegerc")):
                shutil.copy(
                    os.path.join(filesystem.get_home_dir(), ".solfegerc"),
                    filesystem.rcfile())
    except (IOError, os.error) as e:
        print("Migration failed:", e)

from solfege import presetup
presetup.presetup("default.config", None, filesystem.rcfile())

# i18n should be imported very early in program init because it setup
# the _ and _i functions for the whole program.

from solfege import i18n
i18n.setup(".", cfg.get_string("app/lc_messages"))
import solfege.startup
solfege.startup.start_app(".")
Exemplo n.º 4
0

from __future__ import absolute_import

import logging
import os
import StringIO
import subprocess

import gtk

from solfege.esel import SearchView

if __name__ == '__main__':
    from solfege import i18n
    i18n.setup(".", "C")
    import solfege.statistics
    solfege.db = solfege.statistics.DB()

import solfege
from solfege import cfg
from solfege import filesystem
from solfege import gu
from solfege import frontpage as pd
from solfege import lessonfile
from solfege import osutils

class LessonFilePreviewWidget(gtk.VBox):
    def __init__(self, model):
        gtk.VBox.__init__(self)
        self.m_model = model
Exemplo n.º 5
0
#!/usr/bin/python
# GNU Solfege - free ear training software
# Copyright (C) 2009 Tom Cato Amundsen
# Licence is GPL, see file COPYING

from __future__ import absolute_import
import sys
sys.path.insert(0, ".")

import textwrap
from solfege import i18n
i18n.setup(".")
from solfege import statistics

print 
print "\n".join(textwrap.wrap( 
 "The hash value is calculated using solfege.statistics.hash_of_lessonfile(filename). "
 "This is the sha1 hash value of the file after lines starting with # and empty "
 "lines have been removed."))

print
print "filename:", sys.argv[1]
print "    replaces = \"%s\"" % statistics.hash_of_lessonfile(unicode(sys.argv[1]))
print
Exemplo n.º 6
0
 def setUp(self):
     self.__saved_LANGUAGE = os.environ.get("LANGUAGE", None)
     os.environ["LANGUAGE"] = "nb"
     i18n.setup(".")
Exemplo n.º 7
0
"""
Generate sha1 hash value of a file after removing lines
starting with # and empty lines.

This used to preserve the statistics of lesson files when
doing changes to them that does not affect the statistics.

Usage:
 ./tools/hash-of-file.py filename
"""

import sys
sys.path.insert(0, ".")

if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
   import __main__
   print(__main__.__doc__)
   sys.exit()
import textwrap
from solfege import i18n
i18n.setup(".")
from solfege import statistics

print()
print("\n".join(textwrap.wrap(
 "To preserve statistics, place the following in the header "
 "of %s before making changes to it:" % sys.argv[1])))
print()
print("    replaces = \"%s\"" % statistics.hash_of_lessonfile(str(sys.argv[1])))
print()
Exemplo n.º 8
0
 def setUp(self):
     self.__saved_LANGUAGE = os.environ.get('LANGUAGE', None)
     os.environ['LANGUAGE'] = 'nb'
     i18n.setup(".")
Exemplo n.º 9
0
from solfege import cfg
from solfege import filesystem

if sys.platform == 'win32':
    # Migration added in solfege 3.9.0.
    try:
        if not os.path.exists(filesystem.app_data()):
            if os.path.exists(os.path.join(filesystem.get_home_dir(), ".solfege")):
                shutil.copytree(os.path.join(filesystem.get_home_dir(), ".solfege"),
                                filesystem.app_data())
            else:
                os.mkdir(filesystem.app_data())
        if not os.path.exists(filesystem.rcfile()):
            if os.path.exists(os.path.join(filesystem.get_home_dir(), ".solfegerc")):
                shutil.copy(os.path.join(filesystem.get_home_dir(), ".solfegerc"),
                            filesystem.rcfile())
    except (IOError, os.error) as e:
        print("Migration failed:", e)

from solfege import presetup
presetup.presetup("default.config", None, filesystem.rcfile())

# i18n should be imported very early in program init because it setup
# the _ and _i functions for the whole program.

from solfege import i18n
i18n.setup(".", cfg.get_string("app/lc_messages"))
import solfege.startup
solfege.startup.start_app(".")
Exemplo n.º 10
0
#!/usr/bin/python
import sys
sys.path.insert(0, ".")
from solfege import i18n
i18n.setup(".", "C")
from solfege import cfg
from solfege import filesystem
cfg.initialise("default.config", None, filesystem.rcfile())
from solfege import soundcard
from solfege.mpd import Track

# This works nice with ALSA and OSS emulation with SB Live card:
soundcard.initialise_external_midiplayer()
#soundcard.initialise_devicefile("/dev/sequencer2", 2)


print """
You should here three major triads:

    G       G       G
  E       E       E_E
C       C       C_C_C   C
(piano) (flute) (strings ens)

Press enter when the sounds are finished.
"""

t = Track()
t.set_bpm(120, 4)
t.note(4, 60, 100)
t.note(4, 64, 100)
Exemplo n.º 11
0
 def setUp(self):
     self.__saved_LANGUAGE = os.environ.get('LANGUAGE', None)
     os.environ['LANGUAGE'] = 'nb'
     i18n.setup(".")