def make_zip(filelist): """ :type filelist: list """ # Main path in tarfile: maindir = 'DSR-{}/'.format(VERSION) # tmpdir for file collection: tmpdir = tempfile.mkdtemp() # full directory in temp: full_tmp_dir = os.path.abspath(os.path.join(tmpdir, maindir)) os.makedirs(full_tmp_dir) # Tar output file zipfilename = os.path.abspath('setup/Output/DSR-{}.tar.gz'.format(VERSION)) remove_file(zipfilename) # Go through DSR path and add files from list: for f in filelist: # Also add recoursive dirs: for filen in walkdir(f, exclude=['.pyc', '.DS_Store']): print(filen) # need path without filename to create target directories: path, _ = os.path.split(filen) target_tmp_dir = os.path.join(full_tmp_dir, path) if not os.path.exists(target_tmp_dir): os.makedirs(target_tmp_dir) copy_file(filen, target_tmp_dir) dos2unix(os.path.join(target_tmp_dir, os.path.split(filen)[1])) # dos2unix only in target tmp with tarfile.open(zipfilename, mode='w:gz') as archive: archive.add(full_tmp_dir, arcname=maindir, recursive=True) # copy_file(zipfilen, 'StructureFinder/scripts/Output/') print("\nFile written to {}".format(zipfilename)) shutil.rmtree(tmpdir) make_shasum(zipfilename)
def make_shasum(filename): sha = sha512_checksum(filename) shafile = os.path.abspath('setup/Output/DSR-{}-sha512.sha'.format(VERSION)) remove_file(shafile) with open(shafile, 'w') as f: f.write(sha) print("SHA512: {}".format(sha))
def setUp(self): import db self.maxDiff = None self.res_file = 'p21c.res' testresfile = './p21c.res' invert = True class OptionsParser(): rigid_group = False target_coords = False self.options = OptionsParser() self.rl = ResList(testresfile) self.reslist = self.rl.get_res_list() self.dsrp = DSRParser(self.reslist) self.find_atoms = FindAtoms(self.reslist) self.gdb = dbfile.ParseDB() fragment = 'OC(CF3)3' self.dbatoms = self.gdb.get_atoms(fragment) # only the atoms of the dbentry as list self.dbhead = self.gdb.get_restraints(fragment) # this is only executed once self.resi = Resi(self.dsrp, 'CF3', self.find_atoms) self.dbtypes = get_atomtypes(self.dbatoms) with open('./intern.TXT') as txt: self.intern = txt.read() with open('./extern.TXT') as txt2: self.extern = txt2.read() misc.remove_file('./dsr_CF3_4_dsr_CF3_p21c.dfix') self.sf = SfacTable(self.reslist, self.dbtypes) self.sfac_table = self.sf.set_sfac_table() self.num = NumberScheme(self.reslist, self.dbatoms, self.dsrp) self.numberscheme = self.num.get_fragment_number_scheme() self.db_testhead = db.db_testhead
def artwork_set_image(self, filename, artist, album, path, info_img_only=False): # Note: filename arrives here is in FILESYSTEM_CHARSET, not UTF-8! if (self.status_is_play_or_pause() and self.songinfo and self.songinfo.get('artist') == artist and self.songinfo.get('album') == album): if os.path.exists(filename): # We use try here because the file might exist, but might # still be downloading or corrupt: try: pix = gtk.gdk.pixbuf_new_from_file(filename) except: # If we have a 0-byte file, it should mean that # sonata reset the image file. Otherwise, it's a # bad file and should be removed. if os.stat(filename).st_size != 0: misc.remove_file(filename) return self.currentpb = pix if not info_img_only: # Store in cache cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, filename) # Artwork for tooltip, left-top of player: (pix1, w, h) = img.get_pixbuf_of_size(pix, 75) pix1 = self.artwork_apply_composite_case(pix1, w, h) pix1 = img.pixbuf_add_border(pix1) pix1 = img.pixbuf_pad(pix1, 77, 77) self.albumimage.set_from_pixbuf(pix1) self.artwork_set_tooltip_art(pix1) del pix1 # Artwork for library, if current song matches: self.library_set_image_for_current_song(cache_key) # Artwork for fullscreen self.fullscreen_cover_art_set_image() # Artwork for info tab: if self.info_imagebox_get_size_request()[0] == -1: fullwidth = self.notebook_get_allocation()[2] - 50 (pix2, w, h) = img.get_pixbuf_of_size(pix, fullwidth) else: (pix2, w, h) = img.get_pixbuf_of_size(pix, 150) pix2 = self.artwork_apply_composite_case(pix2, w, h) pix2 = img.pixbuf_add_border(pix2) self.info_image.set_from_pixbuf(pix2) del pix2 del pix self.lastalbumart = filename self.schedule_gc_collect()
def artwork_set_image(self, filename, artist, album, path, info_img_only=False): # Note: filename arrives here is in FILESYSTEM_CHARSET, not UTF-8! if self.artwork_is_for_playing_song(filename): if os.path.exists(filename): # We use try here because the file might exist, but might # still be downloading or corrupt: try: pix = gtk.gdk.pixbuf_new_from_file(filename) except: # If we have a 0-byte file, it should mean that # sonata reset the image file. Otherwise, it's a # bad file and should be removed. if os.stat(filename).st_size != 0: misc.remove_file(filename) return self.currentpb = pix if not info_img_only: # Store in cache cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, filename) # Artwork for tooltip, left-top of player: (pix1, w, h) = img.get_pixbuf_of_size(pix, 75) pix1 = self.artwork_apply_composite_case(pix1, w, h) pix1 = img.pixbuf_add_border(pix1) pix1 = img.pixbuf_pad(pix1, 77, 77) self.albumimage.set_from_pixbuf(pix1) self.artwork_set_tooltip_art(pix1) del pix1 # Artwork for library, if current song matches: self.library_set_image_for_current_song(cache_key) # Artwork for fullscreen self.fullscreen_cover_art_set_image() # Artwork for info tab: if self.info_imagebox_get_size_request()[0] == -1: fullwidth = self.notebook_get_allocation()[2] - 50 (pix2, w, h) = img.get_pixbuf_of_size(pix, fullwidth) else: (pix2, w, h) = img.get_pixbuf_of_size(pix, 150) pix2 = self.artwork_apply_composite_case(pix2, w, h) pix2 = img.pixbuf_add_border(pix2) self.info_image.set_from_pixbuf(pix2) del pix2 del pix self.lastalbumart = filename self.schedule_gc_collect()
def library_get_album_cover(self, dirname, artist, album, pb_size): _tmp, coverfile = self.artwork_get_local_image(dirname, artist, album) if coverfile: try: coverpb = gtk.gdk.pixbuf_new_from_file_at_size(coverfile, pb_size, pb_size) except: # Delete bad image: misc.remove_file(coverfile) return (None, None) w = coverpb.get_width() h = coverpb.get_height() coverpb = self.artwork_apply_composite_case(coverpb, w, h) return (coverpb, coverfile) return (None, None)
def restore_shx_file(self): """ restores filename from backup """ resfile = os.path.abspath(str(self.resfile_name + '.res')) try: print('*** Restoring previous res file. ***') shutil.copyfile(self.backup_file, resfile) except IOError: print('Unable to restore res file from {}.'.format(self.backup_file)) try: misc.remove_file(self.backup_file) except IOError: print('Unable to delete backup file {}.'.format(self.backup_file))
def get_lyrics_start(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self._check_for_local_lyrics(filename_artist, filename_title, song_dir) lyrics = "" if filename: # If the lyrics only contain "not found", delete the file and try # to fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki # that prevents lyrics from being found, storing the "not found" # will prevent a future release from correctly fetching the lyrics. try: with open(filename, 'r') as f: lyrics = f.read() except IOError: pass if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self._check_for_local_lyrics(filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: try: with open(filename, 'r') as f: lyrics = f.read() except IOError: pass # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = "%s - %s\n\n" % (filename_artist, filename_title) if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] self._show_lyrics(filename_artist, filename_title, lyrics=lyrics) else: # Fetch lyrics from lyricwiki.org etc. lyrics_fetchers = pluginsystem.get('lyrics_fetching') callback = lambda * args: self.get_lyrics_response( filename_artist, filename_title, song_dir, *args) if lyrics_fetchers: msg = _("Fetching lyrics...") for _plugin, cb in lyrics_fetchers: cb(callback, search_artist, search_title) else: msg = _("No lyrics plug-in enabled.") self._show_lyrics(filename_artist, filename_title, lyrics=msg)
def get_lyrics_start(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self._check_for_local_lyrics(filename_artist, filename_title, song_dir) lyrics = '' if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. try: with open(filename, 'r') as f: lyrics = f.read() except IOError: pass if lyrics == _('Lyrics not found'): misc.remove_file(filename) filename = self._check_for_local_lyrics( filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: try: with open(filename, 'r') as f: lyrics = f.read() except IOError: pass # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = '%s - %s\n\n' % (filename_artist, filename_title) if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] self._show_lyrics(filename_artist, filename_title, lyrics=lyrics) else: # Fetch lyrics from lyrics.wikia.org etc. lyrics_fetchers = pluginsystem.get('lyrics_fetching') callback = lambda *args: self.get_lyrics_response( filename_artist, filename_title, song_dir, *args) if lyrics_fetchers: msg = _('Fetching lyrics...') for _plugin, cb in lyrics_fetchers: cb(callback, search_artist, search_title) else: msg = _('No lyrics plug-in enabled.') self._show_lyrics(filename_artist, filename_title, lyrics=msg)
def on_reset_image(self, _action): if self.songinfo: if 'name' in self.songinfo: # Stream, remove file: misc.remove_file(self.artwork_stream_filename(mpdh.get(self.songinfo, 'name'))) else: # Normal song: misc.remove_file(self.target_image_filename()) misc.remove_file(self.target_image_filename(consts.ART_LOCATION_HOMECOVERS)) # Use blank cover as the artwork dest_filename = self.target_image_filename(consts.ART_LOCATION_HOMECOVERS) emptyfile = open(dest_filename, 'w') emptyfile.close() self.artwork_update(True)
def on_reset_image(self, _action): if self.songinfo: if "name" in self.songinfo: # Stream, remove file: misc.remove_file(self.artwork_stream_filename(mpdh.get(self.songinfo, "name"))) else: # Normal song: misc.remove_file(self.target_image_filename()) misc.remove_file(self.target_image_filename(consts.ART_LOCATION_HOMECOVERS)) # Use blank cover as the artwork dest_filename = self.target_image_filename(consts.ART_LOCATION_HOMECOVERS) try: emptyfile = open(dest_filename, "w") emptyfile.close() except IOError: pass self.artwork_update(True)
# Clean temporary image: misc.remove_file(finaltmpdmg) sys.exit() """ # use instead of webserver stuff above tmpdir = tempfile.mkdtemp() # a temporary directory misc.extract_tarfile(inputfile, tmpdir) selfupdate.move_dir(os.path.join(tmpdir, "DSR-{}".format(version)), '/Volumes/DSR-install/DSR/') # end ######################################################### # Do modification stuff here: misc.copy_file("/Volumes/DSR-install/DSR/setup/dsr-mac", "/Volumes/DSR-install/DSR/dsr") subprocess.call(["chmod", "755", "/Volumes/DSR-install/DSR/dsr"]) # Rename the volume: renamecommand = ["diskutil", "rename", "DSR-install", "DSR-{}".format(version)] subprocess.call(renamecommand) ######################################################### subprocess.call(unmountcommmand) #time.sleep(1) # convert to compressed image: misc.remove_file(dmgname) subprocess.call(convert_to_compressed) # Clean temporary image: misc.remove_file(finaltmpdmg)
def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) search_str = misc.link_markup(_("search"), True, True, self.linkcolor) edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor) if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. f = open(filename, 'r') lyrics = f.read() f.close() if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self.info_check_for_local_lyrics( filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: f = open(filename, 'r') lyrics = f.read() f.close() # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = filename_artist + " - " + filename_title + "\n\n" if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) else: # Use default filename: filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir) # Fetch lyrics from lyricwiki.org gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title) if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy( wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: socketsettimeout(timeout) lyrics = _("Couldn't connect to LyricWiki") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) self.lyricServer = None gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong( artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format( search_title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) # Save lyrics to file: misc.create_dir('~/.lyrics/') f = open(filename, 'w') lyrics = misc.unescape_html(lyrics) try: f.write(lyrics.decode(self.enc).encode('utf8')) except: f.write(lyrics) f.close() else: lyrics = _("Lyrics not found") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) except: lyrics = _("Fetching lyrics failed") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) socketsettimeout(timeout)
def check_refinement_results(self, list_file): """ Does some checks if the refinement makes sense e.g. if the data to parameter ratio is in an acceptable range. :param list_file: SHELXL listing file :type list_file: list """ is_resfile_there = misc.check_file_exist(self.resfile_name + '.res') if is_resfile_there and is_resfile_there == 'zero': print('Something failed in SHELXL. Please check your .ins and .lst file!') self.restore_shx_file() try: misc.remove_file(self.backup_file) except IOError: print('Unable to delete backup file {}.'.format(self.backup_file)) sys.exit() if not is_resfile_there: print('Something failed in SHELXL. Please check your .ins and .lst file!') self.restore_shx_file() try: misc.remove_file(self.backup_file) except IOError: print('Unable to delete backup file {}.'.format(self.backup_file)) sys.exit() regex_final = r' Final Structure Factor Calculation.*\n' final_results = find_line(list_file, regex_final) # find data and parameters: try: dataobj = re.search(r'[0-9]+\s+data', list_file[final_results + 4]) data = float(dataobj.group(0).split()[0]) parameterobj = re.search(r'[0-9]+\s+parameters', list_file[final_results + 4]) parameters = float(parameterobj.group(0).split()[0]) restrobj = re.search(r'[0-9]+\s+restraints', list_file[find_line(list_file, r" GooF = S =.*")]) restraints = float(restrobj.group(0).split()[0]) except AttributeError: return False try: data_to_parameter_ratio = data / parameters restr_ratio = ((data + restraints) / parameters) except ZeroDivisionError: return False lattline = find_line(list_file, r'^ LATT.*') centro = None if lattline: try: latt = int(list_file[lattline].split()[1]) except ValueError: latt = False if latt > 0: centro = True else: centro = False if centro and data_to_parameter_ratio < 10: print('*** Warning! The data/parameter ratio is getting low (ratio = {:.1f})! ***' '\n*** but consider (data+restraints)/parameter = {:.1f} ***' .format(data_to_parameter_ratio, restr_ratio)) if not centro and data_to_parameter_ratio < 7.5: print('*** Warning! The data/parameter ratio is getting low (ratio = {:.1f})! ***' '\n*** but consider (data+restraints)/parameter = {:.1f} ***' .format(data_to_parameter_ratio, restr_ratio)) try: misc.remove_file(self.backup_file) except IOError: print('Unable to delete backup file {}.'.format(self.backup_file))
def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) search_str = misc.link_markup(_("search"), True, True, self.linkcolor) edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor) if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. f = open(filename, 'r') lyrics = f.read() f.close() if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: f = open(filename, 'r') lyrics = f.read() f.close() # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = filename_artist + " - " + filename_title + "\n\n" if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) else: # Use default filename: filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir) # Fetch lyrics from lyricwiki.org gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title) if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy(wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: socketsettimeout(timeout) lyrics = _("Couldn't connect to LyricWiki") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) self.lyricServer = None gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong(artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format(search_title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) # Save lyrics to file: misc.create_dir('~/.lyrics/') f = open(filename, 'w') lyrics = misc.unescape_html(lyrics) try: f.write(lyrics.decode(self.enc).encode('utf8')) except: f.write(lyrics) f.close() else: lyrics = _("Lyrics not found") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) except: lyrics = _("Fetching lyrics failed") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) socketsettimeout(timeout)
""" This file is used to export the DSR database to sqlite for Olex2. Every fragemnt needs a picture with the same name as the fragment tag in ./pictures """ import os import sqlite3 as lite import sys import misc from constants import SHX_CARDS from dbfile import ParseDB misc.remove_file('./fragment-database.sqlite') gl = ParseDB() db = gl.parse(dbpath="./olex_dsr_db.txt", dbname='olex_db') dbfilename = 'fragment-database.sqlite' con = lite.connect(dbfilename) con.text_factory = str cur = con.cursor() def get_fragment_atoms_cartesian(fragment): """ returns the coordinates of the fragment as cartesian coords as list of lists [['-2.7538', '15.9724', '22.6810'], ['0.7939', '16.3333', '21.3135'], ... :param fragment: :type fragment: """ from export import Export ex = Export(gl, invert=False)