Ejemplo n.º 1
0
    def __build_cache(self):
        def walker(top_dir, dir_name, fnames):
            dir_name = resource.MB(dir_name)
            for fname in fnames:
                fname = resource.MB(fname)
                full_name = os.path.join(dir_name, fname)
                x = self.read_script(full_name)

                if not x:
                    continue

                (sn, sd, ss, rn) = x

                if not rn:
                    continue

                self.__cache[rn] = (full_name,
                                    resource.os_path_getmtime(full_name))

        self.__cache = {}
        os.path.walk(resource.WC(self.__factorydir), walker,
                     resource.WC(self.__factorydir))
        os.path.walk(resource.WC(self.__userdir), walker,
                     resource.WC(self.__userdir))
        print 'rebuilt cache:', len(self.__cache), 'named scripts'
Ejemplo n.º 2
0
def file_bug(user, email, subj, desc):
    try:
        zf = resource.get_bugfile()
        zip = zipfile.ZipFile(resource.WC(zf), 'w')

        zip.writestr('description', desc)
        zip.writestr('user', user)
        zip.writestr('email', email)
        zip.writestr('subject', subj)

        zip.writestr(
            'bugreport.txt',
            "From: %s <%s>\n\nSubject: %s\n\n%s\n" % (user, email, subj, desc))

        def_state_file = resource.user_resource_file(resource.global_dir,
                                                     resource.current_setup)
        for statefile in resource.glob_glob(def_state_file + '*'):
            zip.write(resource.WC(statefile),
                      resource.WC(
                          os.path.join('Setup', os.path.basename(statefile))),
                      compress_type=zipfile.ZIP_DEFLATED)

        # add the crash reports of today to the bug report
        if resource.is_macosx():
            diag = os.path.expanduser("~/Library/Logs/DiagnosticReports")
            today = datetime.date.today().strftime("_%Y-%m-%d-")
            if resource.os_path_isdir(diag):
                for crashfile in resource.glob_glob("%s/eigen*%s*.crash" %
                                                    (diag, today)):
                    zip.write(crashfile,
                              os.path.join("Crash",
                                           os.path.basename(crashfile)),
                              compress_type=zipfile.ZIP_DEFLATED)
                for crashfile in resource.glob_glob("%s/Workbench*%s*.crash" %
                                                    (diag, today)):
                    zip.write(crashfile,
                              os.path.join("Crash",
                                           os.path.basename(crashfile)),
                              compress_type=zipfile.ZIP_DEFLATED)

        #core_files = resource.glob_glob('/cores/*')
        #if core_files:
        #    zip.write( core_files[0],compress_type=zipfile.ZIP_DEFLATED)

        log_folder = resource.user_resource_dir(resource.log_dir)
        for file in resource.glob_glob(os.path.join(log_folder, "*")):
            path, filename = os.path.split(file)
            full_path = os.path.join('Log', filename)
            zip.write(resource.WC(file),
                      resource.WC(full_path),
                      compress_type=zipfile.ZIP_DEFLATED)

        zip.close()
    except:
        utils.log_exception()
Ejemplo n.º 3
0
 def describe(self, id):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute("""select name,desc from files where id=?""",
                    (id, )).fetchone()
     name = str(r[0]) if r[0] else None
     desc = str(r[1]) if r[1] else None
     return name, desc
Ejemplo n.º 4
0
 def rename(self, id, name):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     c = cx.cursor()
     c.execute("""update files set name=? where id=?""",
               (str(name), int(id)))
     c.close()
     cx.commit()
Ejemplo n.º 5
0
    def __read_fingering(self, filename):
        config = ConfigParser.ConfigParser()
        fingerings_from_this_file = {}
        message = ''

        try:
            config.read(resource.WC(filename))

            for fingering_name in config.sections():
                try:
                    options = config.options(fingering_name)
                    fingering_name = fingering_name.strip()
                    fingerings_from_this_file[fingering_name] = [[], [], [],
                                                                 [], None]

                    for option in options:
                        line = config.get(fingering_name, option)
                        pattern = [[], []]
                        keys, targets = line.split('*', 2)
                        targets = targets.strip()

                        if keys.count('open'):
                            fingerings_from_this_file[fingering_name][4] = True
                            pattern[0].append(float(targets.strip()))
                            pattern[1].append(('0', '0'))
                            i = 0
                        else:
                            for target in targets.split(' '):
                                pattern[0].append(float(target.strip()))

                            keys = keys.strip()
                            coords = keys.split(' ')

                            for coord in coords:
                                coord.strip()
                                course, key = coord.split(',', 2)
                                pattern[1].append((course, key))

                            if option.count('finger'): i = 0
                            elif option.count('mod'): i = 1
                            elif option.count('add'): i = 2
                            elif option.count('poly'):
                                i = 3
                                if len(pattern[1]) > 1:
                                    raise FingeringError(
                                        'More than one activation key defined for a polyphony note'
                                    )

                        fingerings_from_this_file[fingering_name][i].append(
                            pattern)

                except FingeringError, e:
                    raise FingeringError("In fingering: '%s', %s" %
                                         (fingering_name, e.args[0]))
                except:
                    raise FingeringError("In fingering: '%s', unknown error" %
                                         fingering_name)

                print 'added', fingering_name, 'from', filename
Ejemplo n.º 6
0
 def __scandir(self, n, frows, mrows, path):
     for root, dirs, files in resource.safe_walk(path):
         for f in files:
             try:
                 if f.startswith('.') or f.startswith('_'):
                     continue
                 (b, e) = os.path.splitext(f)
                 if e.lower() == '.aiff' or e.lower() == '.aif':
                     p = os.path.join(root, f)
                     tags = self.__getmeta(p)
                     frows.append((n, resource.WC(b), resource.WC(p),
                                   resource.WC(f)))
                     mrows.extend([(n, t) for t in tags])
                     n = n + 1
                     if n % 500 == 0: print '%d loops indexed' % n
             except:
                 pass
     return n
Ejemplo n.º 7
0
    def load_file(self, path):
        print 'loading', path
        node = cElementTree.parse(resource.WC(path))

        assert node.getroot().tag == 'documentation'

        for a in node.findall('agent'):
            d = self.load_node(a, None)
            self.__agents[d.label] = d
Ejemplo n.º 8
0
 def finfo(self, path):
     if len(path) > 0:
         if path[0] == factory_cat:
             return self.finfo_path(self.__factorydir, path[1:])
         if path[0] == user_cat:
             return self.finfo_path(self.__userdir, path[1:])
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute(qfinfo(path)).fetchall()
     return r
Ejemplo n.º 9
0
    def __modtime(self):
        cx = sqlite3.connect(resource.WC(self.__dbfile))
        tables = cx.execute(qtables()).fetchall()
        for t in tables:
            if 'modtime' in t:
                r = cx.execute(qmodtime()).fetchall()
                return r

        print 'modtime not in tables'
        return 0
Ejemplo n.º 10
0
def send_bug(bug):
    zip = zipfile.ZipFile(resource.WC(bug), 'r')
    subject = zip.read('subject')
    user = zip.read('user')
    email = zip.read('email')
    description = zip.read('description')

    fields = (('subject', subject), ('from', email), ('description',
                                                      description))
    files = (('report', 'report.zip', resource.file_open(bug, 'rb').read()), )

    post_multipart('www.eigenlabs.com', '/bugfiler/', fields, files)
Ejemplo n.º 11
0
    def idforfile(self, filename):
        cx = sqlite3.connect(resource.WC(self.__dbfile))
        r = cx.execute("""select id from files where file=?""",
                       (filename, )).fetchone()

        if r:
            return (filename, r[0])

        basename = os.path.basename(filename)
        r = cx.execute("""select id,file from files where basename=?""",
                       (basename, )).fetchone()

        if r:
            return (str(r[1]), str(r[0]))

        return (filename, None)
Ejemplo n.º 12
0
    def enumerate(self, path):
        self.__check_modtime()

        if len(path) > 0:
            if path[0] == factory_cat:
                return self.enumerate_path(self.__factorydir, path[1:])
            if path[0] == user_cat:
                return self.enumerate_path(self.__userdir, path[1:])

        cx = sqlite3.connect(resource.WC(self.__dbfile))
        nf = cx.execute(qfilecount(path)).fetchone()[0]
        nc = cx.execute(qdircount(path)).fetchone()[0]

        if len(path) == 0:
            nc = nc + 2
        return (nf, nc)
Ejemplo n.º 13
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.º 14
0
    def scan(self, mtime1=None, mtime2=None):
        print 'building database...'
        cx = sqlite3.connect(resource.WC(self.__dbfile))
        cx.execute(
            """create table files (id int primary key,name text,desc text,file text, basename text)"""
        )
        cx.execute("""create table meta (id int,tag text)""")
        cx.execute("""create table modtime (id int, time int)""")

        files = []
        meta = []
        nxt = 0
        nxt = self.__scandir(
            nxt, files, meta,
            os.path.join(picross.global_resource_dir(), 'loop'))
        nxt = self.__scandir(nxt, files, meta,
                             resource.user_resource_dir(resource.loop_dir, ''))
        print '%d loops indexed' % nxt

        if not mtime1:
            mtime1 = self.__get_modtime(
                resource.user_resource_dir(resource.loop_dir, ''))

        if not mtime2:
            mtime2 = self.__get_modtime(
                os.path.join(picross.global_resource_dir(), 'loop'))

        modtime = [(1, mtime1), (2, mtime2)]

        cx.executemany("""insert into modtime(id,time) values (?,?)""",
                       modtime)
        cx.executemany(
            """insert into files(id,desc,file,basename) values (?,?,?,?)""",
            files)
        cx.executemany("""insert into meta(id,tag) values (?,?)""", meta)
        cx.execute("""create index mx on meta (tag)""")
        cx.commit()
Ejemplo n.º 15
0
 def basename(self, id):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute("""select basename from files where id=?""",
                    (id, )).fetchone()
     if r:
         return str(r[0])
Ejemplo n.º 16
0
 def tags(self, id):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute("""select tag from meta where id=?""",
                    (id, )).fetchall()
     return [str(a[0]) for a in r]
Ejemplo n.º 17
0
 def fileforbasename(self, basename):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute("""select file,id from files where basename=?""",
                    (basename, )).fetchone()
     if r: return r
     return (None, None)
Ejemplo n.º 18
0
 def id(self, name):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute("""select id from files where name=?""",
                    (name, )).fetchone()
     if r:
         return r[0]
Ejemplo n.º 19
0
 def size(self):
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     nf = cx.execute("""select count(*) from files""").fetchone()[0]
     return nf
Ejemplo n.º 20
0
 def finfo_path(self, root, path):
     dir = os.path.join(root, *path)
     cx = sqlite3.connect(resource.WC(self.__dbfile))
     r = cx.execute(qpinfo(dir)).fetchall()
     return r