Ejemplo n.º 1
0
def find_release_resource(category, name):
    res_root = picross.release_resource_dir()
    reldir = os.path.join(res_root, category)

    if not resource.os_path_exists(reldir):
        return None

    filename = os.path.join(reldir, name)

    if resource.os_path_exists(filename):
        return filename

    return None
Ejemplo n.º 2
0
def get_tmp_setup():
    i = 0
    while True:
        dbfile = resource.user_resource_file(resource.setup_dir,
                                             'tmpsetup%d' % i)
        if not resource.os_path_exists(dbfile):
            return dbfile
        i = i + 1
Ejemplo n.º 3
0
 def __init__(self):
     self.__dbfile = os.path.join(
         resource.user_resource_dir(resource.loop_dir), 'loops.db')
     self.__factorydir = os.path.join(picross.global_resource_dir(), 'loop')
     self.__userdir = resource.user_resource_dir(resource.loop_dir, '')
     e = resource.os_path_exists(self.__dbfile)
     if not e:
         self.scan()
     else:
         self.__check_modtime()
     self.prime()
Ejemplo n.º 4
0
    def __get_script(self, name):
        x = self.__cache.get(name)

        if x:
            (file_name, file_time) = x
            if resource.os_path_exists(
                    file_name) and resource.os_path_getmtime(
                        file_name) == file_time:
                return file_name

        return None
Ejemplo n.º 5
0
    def add_extra(self):
        extra_dir = os.path.join(picross.global_library_dir(), 'Global')
        extra = os.path.join(extra_dir, 'paths.txt')

        try:
            resource.os_makedirs(extra_dir)
        except:
            pass

        if not resource.os_path_exists(extra):
            f = resource.file_open(extra, 'w')
            f.write('# add plugin paths here\n')
            f.close()
            return

        paths = resource.file_open(extra, 'r').read()
        for p in paths.splitlines():
            p = p.strip()
            if p.startswith('#'): continue
            if resource.os_path_exists(p):
                self.add_path(p)
Ejemplo n.º 6
0
def __copy_trunk(srcfile, dstfile):
    srcdb = state.open_database(srcfile, False)
    srcsnap = srcdb.get_trunk()

    if resource.os_path_exists(dstfile):
        resource.os_unlink(dstfile)

    dstdb = state.open_database(dstfile, True)
    dstsnap = dstdb.get_trunk()

    copy_snap(srcsnap, dstsnap)
    dstsnap.save(0, '')
    dstdb.flush()
Ejemplo n.º 7
0
    def __init__(self, callback):
        self.__callback = callback

        self.__user_file_name = resource.user_resource_file(
            'Fingerer', 'User Fingerings.txt', version='')
        self.__factory_file_name = os.path.join(os.path.dirname(__file__),
                                                'Factory Fingerings.txt')
        self.__user_seed_file = resource.find_release_resource(
            'fingerer', 'User Fingerings.txt')
        self.__timestamp = piw.tsd_time()
        self.__timer = piw.thing()
        self.__timer.set_slow_timer_handler(utils.notify(
            self.__timer_callback))

        if not resource.os_path_exists(
                self.__user_file_name) and resource.os_path_exists(
                    self.__user_seed_file):
            resource.shutil_copyfile(self.__user_seed_file,
                                     self.__user_file_name)

        self.__user_file_time = 0
        self.__factory_fingerings = {}
        self.__user_fingerings = {}

        self.__load_factory()
        self.__load_user()

        fn = set(self.__factory_fingerings.keys())
        fn.update(set(self.__user_fingerings.keys()))

        atom.Atom.__init__(self,
                           names='fingering',
                           domain=domain.String(),
                           init='simple whistle',
                           policy=atom.default_policy(self.__change_fingering),
                           protocols='browse')
Ejemplo n.º 8
0
    def __load_user(self):
        if not resource.os_path_exists(self.__user_file_name):
            self.__user_fingerings = {}
            return False

        t = resource.os_path_getmtime(self.__user_file_name)

        if t <= self.__user_file_time:
            return False

        self.__user_fingerings = {}
        self.__user_file_time = t
        (f, e) = self.__read_fingering(self.__user_file_name)

        if e:
            piw.tsd_alert('BAD_FINGERING', 'Fingering File Error', e)
            return False

        self.__user_fingerings = f
        return True
Ejemplo n.º 9
0
    def read_user(self):
        if not resource.os_path_exists(self.__user):
            print 'no scale file', self.__user
            fr = resource.find_release_resource('scale_manager',
                                                'User Scales.txt')
            if not fr:
                print 'no factory scale file', fr
                return
            print 'copy', fr, self.__user
            resource.shutil_copyfile(fr, self.__user)

        cp = ConfigParser.ConfigParser()
        cp.read(resource.WC(self.__user))

        for s in sorted(cp.sections()):
            if not cp.has_option(s, 'intervals'):
                continue
            line = cp.get(s, 'intervals')
            line = line.strip()
            self.add_scale(line, s)
Ejemplo n.º 10
0
def backup(file):
    dir = os.path.dirname(file)
    name = os.path.basename(file)

    spl = name.split()

    if len(spl) > 1:
        num = isint(spl[-1])
        if num is not None:
            name = ' '.join(spl[:-1])
        else:
            num = 1
    else:
        num = 1

    for x in xrange(num, 100000):
        nn = os.path.join(dir, '%s %d' % (name, x))
        if not resource.os_path_exists(nn):
            shutil.move(file, nn)
            return

    resource.os_unlink(file)
Ejemplo n.º 11
0
 def rpc_get_test_data(self,arg):
     print 'getting test data',self.__filename
     f = files.get_ideal(self.id(),'audio',files.FileSystemFile(self.__filename,'audio'),0) if resource.os_path_exists(self.__filename) else '[]'
     print 'got recording',f
     d = self.audio.get_dropout_count()
     print 'got dropouts',d
     return logic.render_term((f,d))