Exemplo n.º 1
0
def not_error(item):
  try:
    Song.byPath(str(item.attrib['ref']))
    return 1
  except:
    turbogears.flash("Missing one or more songs, last missing song: " + item.attrib['ref'].replace('songs/','') + ' . . - song(s) not loaded')
    return 0
Exemplo n.º 2
0
  def songbook_edit(self, path):

    # we check to see if the user is trying to hack us with a bad path
    pathcheck(path)

    songbook = Songbook.byPath(str(path))
    path = songbook.path
    songbook_content = open(songbook.path, "rU").read()
    title = c.grab_title(songbook_content)
    sb_xml = parse(songbook.path)

    #same as in songbook_view above
    item_els = sb_xml.getroot().getchildren()
    songbook_items=[]
    for item in item_els:
      if item.tag == 'songref':
        songbook_items.append((Song.byPath(str(item.attrib['ref'])).title, item.attrib['ref'], item.get('status','n')))
      if item.tag == 'section':
        songbook_items.append((item.attrib['title'],'','section'))

    password = ''
    if sb_xml.find('password') != None:
      password = sb_xml.find('password').text 

    return dict(title=title, path=path, new=False, songs_list=db.songs(), songbooks=db.songbooks(), songbook_items=songbook_items, password=password, def_title="New Songbook")
Exemplo n.º 3
0
  def song_view_content(self, path):
    # we check to see if the user is trying to hack us with a bad path
    pathcheck(path)
    
    try:
      song = Song.byPath(str(path))
    except SQLObjectNotFound:
      raise cherrypy.HTTPRedirect(URL("/notfound?path=%s" % path))

    songXML = open(song.path).read()
    return songXML
Exemplo n.º 4
0
  def export_form(self, path="songs/jesujesu.son", selected="simple.cfg"):
    # we check to see if the user is trying to hack us with a bad path
    pathcheck(path)
    
    try:
      if 'songbook'in path:
        exportS = Songbook.byPath(str(path))
      elif 'song' in path:
        exportS = Song.byPath(str(path))
      else:
        raise cherrypy.HTTPRedirect(URL("/notfound?path=%s" % path))


    except SQLObjectNotFound:
      raise cherrypy.HTTPRedirect(URL("/notfound?path=%s" % path))
    title = exportS.title

    cf_dir = "config_files/"
    # grab all the paths for the config files
    config_paths = glob.glob(cf_dir + "*")
    config_files = dict()

    # for loop reads stylesheets and packages them in a list of dictionaries
    for c_path in config_paths:
      tmp_dict = dict()
      # read path and dump contents in tmp

      for line in open(c_path, "rU"):
        line = line.replace('--','').replace('-','_').split()
        if len(line) == 2:
          tmp_dict[line[0]]=line[1].replace('_','-')

      #config_files[c_path.replace(cf_dir,'')]=tmp_dict
      config_files[os.path.basename(c_path)]=tmp_dict

    songbook_configs = dict()
    songbook_xml = parse(path)
    for format_config in songbook_xml.findall('//formatter'):
      key = format_config.get('name')
      config_val = dict()

      # parse the config_val dict from the xml element content
      raw_args = format_config.text.replace('--', '').replace('-', '_').split()
      for i in range(0, len(raw_args), 2):
        if i+1 < len(raw_args): # can't go out of bounds
          config_val[raw_args[i]] = raw_args[i+1].replace('_', '-')

      # lets store this key and config
      songbook_configs[key] = config_val
    # done parsing songbook_configs

    #DEBUG:  print config_files
    return dict(title=title, path=path, config_files=config_files, songbook_configs=songbook_configs, songbooks=db.songbooks(), selected=selected)
Exemplo n.º 5
0
  def song_edit(self, path):

    # we check to see if the user is trying to hack us with a bad path
    pathcheck(path)

    song = Song.byPath(str(path))
    path = song.path
    song_xml = ET.parse(path)

    # get information from song_xml
    title = 'Untitled' 
    author = ''
    scripture_ref =''
    intro = ''
    key = ''
    copyrights = ''
    cclis = None 
    categories = '' 

    if song_xml.find('stitle') != None:
      title = song_xml.find('stitle').text 
    if song_xml.find('author') != None:
      author = song_xml.find('author').text
    if song_xml.find('scripture_ref') != None:
      scripture_ref = song_xml.find('scripture_ref').text
    if song_xml.find('introduction') != None:
      intro = song_xml.find('introduction').text
    if song_xml.find('key') != None:
      key = song_xml.find('key').text
    if song_xml.find('copyright') != None:
      copyrights = song_xml.find('copyright').text
    if song_xml.find('cclis') != None:
      cclis = song_xml.find('cclis').text
    if song_xml.find('categories') != None and song_xml.find('categories').text != None:
      categories = [cat.strip() for cat in song_xml.find('categories').text.split(',')]

    chunks = song_xml.findall('chunk')

    for chunk in chunks:
      chunk_text=[]
      lines = chunk.findall('line')
      for line in lines:
        if song2mono.is_chord_line(ET.tostring(line))==1:
          chunk_text.append(song2mono.expand_chord(ET.tostring(line)))
        else:
          chunk_text.append(line.text or "")

      chunk.text = '\n'.join(chunk_text)

    return dict(title=title, author=author, scripture_ref=scripture_ref, introduction=intro, key=key, copyrights=copyrights, chunks=chunks, path=path, new=False, songbooks=db.songbooks(), cclis=cclis, categories=categories, def_title="New Song")
Exemplo n.º 6
0
  def songbook_view(self, path=c.ALL_SONGS_PATH):
    # we check to see if the user is trying to hack us with a bad path
    pathcheck(path)

    if path == c.ALL_SONGS_PATH:
      #create songbook all songs from scratch and save in location.  Then pass it to be viewed

      title = "All Songs"
      songbook_content = '''<songbook format-version="0.1">\n<title>''' + title.strip() + "</title>"

      #get all paths and sort them
      songs = [songs for songs in Song.select(orderBy=Song.q.title)]
      songs.sort(key=lambda x: x.title.lower() or 'No Title')
      
      for song in songs:
        songbook_content = songbook_content + '\n<songref ref="' + song.path +'" status="n"/>'
      
      songbook_content = songbook_content + '\n</songbook>'
      
      write = open(path, "w")
      write.write(songbook_content)
      write.close()
      
      try:
        all_songs_songbook = Songbook.byPath(str(path))
      except SQLObjectNotFound:
        all_songs_songbook = Songbook(title=title, path=str(path))

    try:
      if path != c.ALL_SONGS_PATH:
        #look up title from database
        songbook = Songbook.byPath(str(path))
        title = songbook.title
    except SQLObjectNotFound:
      raise cherrypy.HTTPRedirect(URL("/notfound?path=%s" % path))
    

    sb_xml = parse(path)

    #same as in songbook_edit below 
    item_els = sb_xml.getroot().getchildren()
    songbook_items=[]
    for item in item_els:
      if item.tag == 'songref':
        songbook_items.append((Song.byPath(str(item.attrib['ref'])).title, item.attrib['ref'], item.get('status','n')))
      if item.tag == 'section':
        songbook_items.append((item.attrib['title'],'','section'))

    return dict(title=title, path=path, songbook_items=songbook_items, songbooks=db.songbooks())
Exemplo n.º 7
0
 def song_title(f):
   try:
     return Song.byPath(str(f)).title, 
   except SQLObjectNotFound:
     return '[SONG NOT IN DATABASE -- REPORT THIS]'