Ejemplo n.º 1
0
def merge_db(src_db, dst_db):  # FIXME
    merged = 0
    dst_db.session.rollback()  # cancel all pending operations
    src_session = src_db.Session()  # create new session
    dst_session = dst_db.Session()  # create new session
    movies = src_session.query(db.Movie).count()
    for movie in src_session.query(db.Movie).all():
        if dst_session.query(db.Movie).filter_by(o_title=movie.o_title).first() is not None:
            continue
        t_movies = {}
        for column in movie.mapper.c.keys():
            t_movies[column] = eval("movie.%s" % column)

        # replace number with new one
        t_movies["number"] = gutils.find_next_available(dst_db)

        # don't restore volume/collection/tag/language/loan data (it's dangerous)
        t_movies.pop('movie_id')
        t_movies.pop('loaned')
        t_movies.pop('volume_id')
        t_movies.pop('collection_id')

        if dst_db.add_movie(t_movies):  # FIXME
            print t_movies

        if movie.image is not None:
            dest_file = os.path.join(self.locations['posters'], movie.image + '.jpg')
            if not os.path.isfile(dest_file):
                src_file = os.path.join(tmp_dir, movie.image + '.jpg')
                if os.path.isfile(src_file):
                    move(src_file, dest_file)
        merged += 1
    return merged
Ejemplo n.º 2
0
def merge_db(src_db, dst_db):  # FIXME
    merged = 0
    dst_db.session.rollback()  # cancel all pending operations
    src_session = src_db.Session()  # create new session
    dst_session = dst_db.Session()  # create new session
    movies = src_session.query(db.Movie).count()
    for movie in src_session.query(db.Movie).all():
        if dst_session.query(db.Movie).filter_by(o_title=movie.o_title).first() is not None:
            continue
        t_movies = {}
        for column in movie.mapper.c.keys():
            t_movies[column] = eval("movie.%s" % column)

        # replace number with new one
        t_movies["number"] = gutils.find_next_available(dst_db)

        # don't restore volume/collection/tag/language/loan data (it's dangerous)
        t_movies.pop('movie_id')
        t_movies.pop('loaned')
        t_movies.pop('volume_id')
        t_movies.pop('collection_id')

        if dst_db.add_movie(t_movies):  # FIXME
            print t_movies

        if movie.image is not None:
            dest_file = os.path.join(self.locations['posters'], movie.image + '.jpg')
            if not os.path.isfile(dest_file):
                src_file = os.path.join(tmp_dir, movie.image + '.jpg')
                if os.path.isfile(src_file):
                    move(src_file, dest_file)
        merged += 1
    return merged
Ejemplo n.º 3
0
def add_movie(self):
	quick_filter.clear_filter(self)
	next_number = gutils.find_next_available(self)
	initialize_add_dialog(self)
	self.am_number.set_text(str(next_number))
	self.add_movie_window.show()
	self.active_plugin = ""
Ejemplo n.º 4
0
def add_movie_db(self, close):
	if  len(self.am_original_title.get_text()) or len(self.am_title.get_text()):
		self.db.add_movie(self)
		
		# lets move poster from tmp to posters dir
		tmp_dest = os.path.join(self.griffith_dir, "posters")
		
		if self.windows:
			temp_dir = "C:\\windows\\temp\\"
		else:
			temp_dir = "/tmp/"
			
		pic = string.replace(self.am_picture_name.get_text()+".jpg",temp_dir,"")
		

		if len(self.am_picture_name.get_text()):
			if os.path.isfile(os.path.join(temp_dir, pic)):
				shutil.move(os.path.join(temp_dir, pic), tmp_dest)
		
		if int(self.am_number.get_text()) >= 2:
			insert_after = self.treemodel.get_iter(int(self.am_number.get_text())-2)
		else:
			insert_after = None
		myiter = self.treemodel.insert_after(None, insert_after)	
	
		if len(self.am_picture_name.get_text()):
			image_path = os.path.join(tmp_dest, pic)
			#lets make the thumbnail and medium image from poster for future use
			gutils.make_thumbnail(self, image_path)
			gutils.make_medium_image(self, image_path)
		else:
			image_path = os.path.join(self.locations['images'], "default.png")
		handler = self.Image.set_from_file(image_path)
		pixbuf = self.Image.get_pixbuf()
		self.treemodel.set_value(myiter, 1, \
			'%004d' % int(self.am_number.get_text()))
		self.treemodel.set_value(myiter, 2, pixbuf.scale_simple(30,40,3))
		self.treemodel.set_value(myiter, \
			3, str(self.am_original_title.get_text()))
		self.treemodel.set_value(myiter, 4, str(self.am_title.get_text()))
		self.treemodel.set_value(myiter, 5, str(self.am_director.get_text()))
		#update statusbar
		self.total += 1
		self.total_filter = self.total
		self.count_statusbar()
		#select new entry from main treelist
		treeselection = self.main_treeview.get_selection()
		treeselection.select_iter(myiter)
		self.main_treeview.set_cursor(int(self.am_number.get_text())-1)
		self.treeview_clicked()
		next_number=gutils.find_next_available(self)
		initialize_add_dialog(self)
		self.am_number.set_text(str(next_number))
		
		if close:
			self.hide_add_movie()
	else:
		gutils.error(self.w_results, \
			_("You should fill the original title\nor the movie title."))
Ejemplo n.º 5
0
def edit_movie(self, details={}):
	if not details.has_key('number'):
		details['number'] = gutils.find_next_available(self.db)
	set_details(self, details)
	self.widgets['add']['add_button'].hide()
	self.widgets['add']['add_close_button'].hide()
	self.widgets['add']['clear_button'].hide()
	self.widgets['add']['save_button'].show()
	self.widgets['add']['window'].set_title(_('Edit movie'))
	self.widgets['add']['window'].show()
Ejemplo n.º 6
0
def edit_movie(self, details={}):
    if not 'number' in details:
        details['number'] = gutils.find_next_available(self.db)
    self.selected_iter_edit = self.selected_iter
    set_details(self, details)
    self.widgets['add']['add_button'].hide()
    self.widgets['add']['add_close_button'].hide()
    self.widgets['add']['clear_button'].show()
    self.widgets['add']['save_button'].show()
    self.widgets['add']['window'].set_title(_('Edit movie'))
    self.widgets['add']['window'].show()
Ejemplo n.º 7
0
def clone_movie(self):
	treeselection = self.widgets['treeview'].get_selection()
	(tmp_model, tmp_iter) = treeselection.get_selected()
	if tmp_iter is None:
		return False
	number = tmp_model.get_value(tmp_iter, 0)
	movie = self.db.Movie.get_by(number=number)

	if movie is None:
		return False

	next_number = gutils.find_next_available(self.db)
	if movie.image is not None:
		new_image = str(movie.image) + '_' + str(next_number)
	else:
		new_image = None
	
	# integer problem workaround
	if int(movie.seen)==1:
		seen = True
	else:
		seen = False
	new_movie = self.db.Movie()
	
	new_movie.cast = movie.cast
	new_movie.classification = movie.classification
	new_movie.vcodec_id = movie.vcodec_id
	new_movie.collection_id = movie.collection_id
	new_movie.volume_id = movie.volume_id
	new_movie.color = movie.color
	new_movie.cond = movie.cond
	new_movie.country = movie.country
	new_movie.director = movie.director
	new_movie.genre = movie.genre
	new_movie.image = new_image
	new_movie.site = movie.site
	new_movie.loaned = movie.loaned
	new_movie.layers = movie.layers
	new_movie.medium_id = movie.medium_id
	new_movie.number = next_number
	new_movie.media_num = movie.media_num
	new_movie.notes = movie.notes
	new_movie.o_title = movie.o_title
	new_movie.plot = movie.plot
	new_movie.rating = movie.rating
	new_movie.region = movie.region
	new_movie.runtime = movie.runtime
	new_movie.seen = seen
	new_movie.o_site = movie.o_site
	new_movie.studio = movie.studio
	new_movie.title = movie.title
	new_movie.trailer = movie.trailer
	new_movie.year = movie.year
	
	new_movie.tags = movie.tags
	new_movie.languages = movie.languages
	new_movie.loans = movie.loans
	
	# save
	new_movie.save()
	new_movie.flush()

	# WARNING: loan problems (don't copy volume/collection data until resolved)

	tmp_dest = self.locations['posters']
	if movie.image is not None:
		image_path = os.path.join(tmp_dest, str(movie.image)+".jpg")
		clone_path = os.path.join(tmp_dest, new_image+".jpg")
		# clone image
		# catch IOError otherwise you would not see the cloned entry in
		# the list before the next start of griffith or another refresh
		# of the list
		try:
			shutil.copyfile(image_path, clone_path)
			image_path = clone_path
			gutils.make_thumbnail(self, "%s.jpg" % new_image)
			gutils.make_medium_image(self, "%s.jpg" % new_image)
		except IOError:
			image_path = os.path.join(self.locations['images'], "default.png")
	else:
		image_path = os.path.join(self.locations['images'], "default.png")
	handler = self.Image.set_from_file(image_path)

	# change_filter calls populate_treeview which updates the status bar
	quick_filter.change_filter(self)
Ejemplo n.º 8
0
def set_details(self, item=None):#{{{
	if item is None:
		item = {}
	if item.has_key('movie_id') and item['movie_id']:
		self._am_movie_id = item['movie_id']
	else:
		self._am_movie_id = None
	w = self.widgets['add']

	cast_buffer  = w['cast'].get_buffer()
	notes_buffer = w['notes'].get_buffer()
	plot_buffer  = w['plot'].get_buffer()

	if item.has_key('o_title') and item['o_title']:
		w['o_title'].set_text(item['o_title'])
	else:
		w['o_title'].set_text('')
	if item.has_key('title') and item['title']:
		w['title'].set_text(item['title'])
	else:
		w['title'].set_text('')
	if item.has_key('number') and item['number']:
		w['number'].set_value(int(item['number']))
	else:
		w['number'].set_value(int(gutils.find_next_available(self.db)))
	if item.has_key('title') and item['title']:
		w['title'].set_text(item['title'])
	if item.has_key('year') and item['year']:
		w['year'].set_value( gutils.digits_only(item['year'], 2100))
	else:
		w['year'].set_value(0)
	if item.has_key('runtime') and item['runtime']:
		w['runtime'].set_value( gutils.digits_only(item['runtime']))
	else:
		w['runtime'].set_value(0)
	if item.has_key('country') and item['country']:
		w['country'].set_text(item['country'])
	else:
		w['country'].set_text('')
	if item.has_key('classification') and item['classification']:
		w['classification'].set_text(item['classification'])
	else:
		w['classification'].set_text('')
	if item.has_key('studio') and item['studio']:
		w['studio'].set_text(item['studio'])
	else:
		w['studio'].set_text('')
	if item.has_key('o_site') and item['o_site']:
		w['o_site'].set_text(item['o_site'])
	else:
		w['o_site'].set_text('')
	if item.has_key('director') and item['director']:
		w['director'].set_text(item['director'])
	else:
		w['director'].set_text('')
	if item.has_key('site') and item['site']:
		w['site'].set_text(item['site'])
	else:
		w['site'].set_text('')
	if item.has_key('trailer') and item['trailer']:
		w['trailer'].set_text(item['trailer'])
	else:
		w['trailer'].set_text('')
	if item.has_key('title') and item['title']:
		w['title'].set_text(item['title'])
	else:
		w['title'].set_text('')
	if item.has_key('genre') and item['genre']:
		w['genre'].set_text(item['genre'])
	else:
		w['genre'].set_text('')
	if item.has_key('color') and item['color']:
		w['color'].set_active( gutils.digits_only(item['color'], 3))
	else:
		w['color'].set_active( gutils.digits_only(self.config.get('color', 0, section='defaults'), 3))
	if item.has_key('layers') and item['layers']:
		w['layers'].set_active( gutils.digits_only(item['layers'], 4))
	else:
		w['layers'].set_active( gutils.digits_only(self.config.get('layers', 0, section='defaults'), 4))
	if item.has_key('region') and item['region']>=0:
			w['region'].set_active( gutils.digits_only(item['region'], 8))
	else:
		w['region'].set_active( gutils.digits_only(self.config.get('region', 0, section='defaults'), 8))
	if item.has_key('cond') and item['cond']>=0:
		w['condition'].set_active( gutils.digits_only( item['cond'], 5) )
	else:
		w['condition'].set_active( gutils.digits_only( self.config.get('condition', 0, section='defaults'), 5))
	if item.has_key('media_num') and item['media_num']:
		w['discs'].set_value( gutils.digits_only(item['media_num']))
	else:
		w['discs'].set_value(1)
	if item.has_key('rating') and item['rating']:
		w['rating_slider'].set_value( gutils.digits_only(item['rating'], 10) )
	else:
		w['rating_slider'].set_value(0)
	if item.has_key('seen') and item['seen'] is True:
		w['seen'].set_active(True)
	else:
		w['seen'].set_active(False)
	if item.has_key('cast') and item['cast']:
		cast_buffer.set_text(item['cast'])
	else:
		cast_buffer.set_text('')
	if item.has_key('notes') and item['notes']:
		notes_buffer.set_text(item['notes'])
	else:
		notes_buffer.set_text('')
	if item.has_key('plot') and item['plot']:
		plot_buffer.set_text(item['plot'])
	else:
		plot_buffer.set_text('')
	pos = 0
	if item.has_key('medium_id') and item['medium_id']:
		pos = gutils.findKey(item['medium_id'], self.media_ids)
	else:
		pos = gutils.findKey(int(self.config.get('media', 0, section='defaults')), self.media_ids)
	if pos is not None:
		w['media'].set_active(int(pos))
	else:
		w['media'].set_active(0)
	pos = 0
	if item.has_key('vcodec_id') and item['vcodec_id']:
		pos = gutils.findKey(item['vcodec_id'], self.vcodecs_ids)
	else:
		pos = gutils.findKey(int(self.config.get('vcodec', 0, section='defaults')), self.vcodecs_ids)
	if pos is not None:
		w['vcodec'].set_active(int(pos))
	else:
		w['vcodec'].set_active(0)
	pos = 0
	if item.has_key('volume_id') and item['volume_id']:
		pos = gutils.findKey(item['volume_id'], self.volume_combo_ids)
	if pos is not None:
		w['volume'].set_active(int(pos))
	else:
		w['volume'].set_active(0)
	pos = 0
	if item.has_key('collection_id') and item['collection_id']:
		pos = gutils.findKey(item['collection_id'], self.collection_combo_ids)
	if pos is not None:
		w['collection'].set_active(int(pos))
	else:
		w['volume'].set_active(0)
	# tags
	for tag in self.am_tags:
		self.am_tags[tag].set_active(False)
	if item.has_key('tags'):
		for tag in item['tags']:
			i = gutils.findKey(tag.tag_id, self.tags_ids)
			self.am_tags[i].set_active(True)
	# languages
	w['lang_treeview'].get_model().clear()
	if item.has_key('languages') and len(item['languages'])>0:
		for i in item['languages']:
			self.create_language_row(i)
	# poster
	if item.has_key('image') and item['image']:
		w['image'].set_text(item['image'])
		image_path = os.path.join(self.locations['posters'], "m_%s.jpg" % item['image'])
	else:
		w['image'].set_text('')
		image_path = os.path.join(self.locations['images'], 'default.png')
	if not os.path.isfile(image_path):
		image_path = os.path.join(self.locations['images'], 'default.png')
	w['picture'].set_from_file(image_path)
	
	w['notebook'].set_current_page(0)
	w['source'].set_active(self.d_plugin)
	w['o_title'].grab_focus()
Ejemplo n.º 9
0
def merge(self):	# FIXME
	"""
		Merge database from:
		* compressed backup
		* SQLite2 *.gri file
		* SQLite3 *.db file
	"""
	filename = gutils.file_chooser(_("Restore Griffith backup"), \
		action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons= \
		(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, \
		gtk.STOCK_OPEN, gtk.RESPONSE_OK))[0]
	if filename:
		from tempfile import mkdtemp
		from shutil import rmtree, move

		#tmp_config={}
		#tmp_config.get('type', 'sqlite', section='database')

		if filename.lower().endswith('.zip'):
			tmp_dir = mkdtemp()
			try:
				zip = zipfile.ZipFile(filename, 'r')
			except:
				gutils.error(self, _("Can't read backup file"), self.widgets['window'])
				return False
			for each in zip.namelist():
				file_to_restore = os.path.split(each)
				if not os.path.isdir(file_to_restore[1]):
					myfile = os.path.join(tmp_dir, file_to_restore[1])
					outfile = open(myfile, 'wb')
					outfile.write(zip.read(each))
					outfile.flush()
					outfile.close()
			# load stored database filename
			tmp_config = config.Config(file=os.path.join(tmp_dir,'griffith.conf'))
			filename = os.path.join(tmp_dir, tmp_config('file', 'griffith.db', section='database'))
			zip.close()

		# check if file needs conversion
		if filename.lower().endswith(".gri"):
			if os.path.isfile(filename) and  open(filename).readline()[:47] == "** This file contains an SQLite 2.1 database **":
				self.debug.show("MERGE: SQLite2 database format detected. Converting...")
				if not self.db.convert_from_sqlite2(filename, os.path.join(tmp_dir, self.config.get('file', 'griffith.db', section='database'))):
					self.debug.show("MERGE: Can't convert database, aborting.")
					return False
		tmp_dir, tmp_file = os.path.split(filename)
		self.config.get('file', tmp_file, section='database') 

		tmp_db = sql.GriffithSQL(tmp_config, self.debug, tmp_dir)

		merged=0
		movies = tmp_db.Movie.count()
		for movie in tmp_db.Movie.select():
			if self.db.Movie.get_by(o_title=movie.o_title) is not None:
				continue
			t_movies = {}
			for column in movie.mapper.c.keys():
				t_movies[column] = eval("movie.%s"%column)

			# replace number with new one
			t_movies["number"] = gutils.find_next_available(self.db)

			# don't restore volume/collection/tag/language/loan data (it's dangerous)
			t_movies.pop('movie_id')
			t_movies.pop('loaned')
			t_movies.pop('volume_id')
			t_movies.pop('collection_id')

			if self.db.add_movie(t_movies):
				print t_movies

			if movie.image is not None:
				dest_file = os.path.join(self.locations['posters'], movie.image+'.jpg')
				if not os.path.isfile(dest_file):
					src_file = os.path.join(tmp_dir, movie.image+'.jpg')
					if os.path.isfile(src_file):
						move(src_file, dest_file)
			merged+=1
		rmtree(tmp_dir)

		from initialize	import dictionaries, people_treeview
		dictionaries(self)
		people_treeview(self)
		# let's refresh the treeview
		self.clear_details()
		self.populate_treeview(self.db.Movie.select())
		self.total = self.db.Movie.count()
		self.count_statusbar()
Ejemplo n.º 10
0
def clone_movie(self):
    treeselection = self.widgets['treeview'].get_selection()
    (tmp_model, tmp_iter) = treeselection.get_selected()
    if tmp_iter is None:
        log.warn("cannot clone movie: no item selected")
        return False
    number = tmp_model.get_value(tmp_iter, 0)
    movie = self.db.session.query(db.Movie).filter_by(number=number).first()

    if movie is None:
        log.warn("cannot clone movie: Movie(%s) not found", number)
        return False

    next_number = gutils.find_next_available(self.db)
    
    # integer problem workaround
    if int(movie.seen)==1:
        seen = True
    else:
        seen = False
    new_movie = db.Movie()
    
    # TODO: WARNING: loan problems (don't copy volume/collection data until resolved)
    new_movie.cast           = movie.cast
    new_movie.classification = movie.classification
    new_movie.vcodec_id      = movie.vcodec_id
    new_movie.cameraman      = movie.cameraman
    new_movie.collection_id  = movie.collection_id
    new_movie.volume_id      = movie.volume_id
    new_movie.color          = movie.color
    new_movie.cond           = movie.cond
    new_movie.country        = movie.country
    new_movie.director       = movie.director
    new_movie.genre          = movie.genre
    new_movie.site           = movie.site
    new_movie.loaned         = movie.loaned
    new_movie.layers         = movie.layers
    new_movie.medium_id      = movie.medium_id
    new_movie.number         = next_number
    new_movie.media_num      = movie.media_num
    new_movie.notes          = movie.notes
    new_movie.o_title        = movie.o_title
    new_movie.plot           = movie.plot
    new_movie.poster_md5     = movie.poster_md5
    new_movie.ratio_id       = movie.ratio_id
    new_movie.rating         = movie.rating
    new_movie.region         = movie.region
    new_movie.runtime        = movie.runtime
    new_movie.screenplay     = movie.screenplay
    new_movie.seen           = seen
    new_movie.o_site         = movie.o_site
    new_movie.studio         = movie.studio
    new_movie.title          = movie.title
    new_movie.trailer        = movie.trailer
    new_movie.year           = movie.year
    
    new_movie.tags           = movie.tags
    new_movie.languages      = movie.languages
    new_movie.loans          = movie.loans
    
    # save
    self.db.session.add(new_movie)
    if not commit(self, self.db.session):
        return False

    image_path = gutils.get_image_fname(movie.poster_md5, self.db)
    if not image_path or not os.path.isfile(image_path):
        image_path = os.path.join(self.locations['images'], 'default.png')
    handler = self.Image.set_from_file(image_path)

    # change_filter calls populate_treeview which updates the status bar
    quick_filter.change_filter(self)
Ejemplo n.º 11
0
def set_details(self, item=None):#{{{
    if item is None:
        item = {}
    if 'movie_id' in item and item['movie_id']:
        self._am_movie_id = item['movie_id']
    else:
        self._am_movie_id = None
    w = self.widgets['add']

    cast_buffer = w['cast'].get_buffer()
    notes_buffer = w['notes'].get_buffer()
    plot_buffer = w['plot'].get_buffer()

    if 'o_title' in item and item['o_title']:
        w['o_title'].set_text(item['o_title'])
    else:
        w['o_title'].set_text('')
    if 'title' in item and item['title']:
        w['title'].set_text(item['title'])
    else:
        w['title'].set_text('')
    if 'number' in item and item['number']:
        w['number'].set_value(int(item['number']))
    else:
        w['number'].set_value(int(gutils.find_next_available(self.db)))
    if 'title' in item and item['title']:
        w['title'].set_text(item['title'])
    if 'year' in item and item['year']:
        w['year'].set_value(gutils.digits_only(item['year'], 2100))
    else:
        w['year'].set_value(0)
    if 'resolution' in item and item['resolution']:
        if self.config.get('use_resolution_alias', True):
            w['resolution'].set_text(item['resolution'])
        elif 'height' in item and item['height'] and 'width' in item and item['width']:
            w['resolution'].set_text("%dx%d" % (item['width'], item['height']))
        else: # failback to 'resolution'
            w['resolution'].set_text(item['resolution'])
    else:
        w['resolution'].set_text('')
    if 'runtime' in item and item['runtime']:
        w['runtime'].set_value(gutils.digits_only(item['runtime']))
    else:
        w['runtime'].set_value(0)
    if 'barcode' in item and item['barcode']:
        w['barcode'].set_text(item['barcode'])
    else:
        w['barcode'].set_text('')
    if 'cameraman' in item and item['cameraman']:
        w['cameraman'].set_text(item['cameraman'])
    else:
        w['cameraman'].set_text('')
    if 'screenplay' in item and item['screenplay']:
        w['screenplay'].set_text(item['screenplay'])
    else:
        w['screenplay'].set_text('')
    if 'country' in item and item['country']:
        w['country'].set_text(item['country'])
    else:
        w['country'].set_text('')
    if 'classification' in item and item['classification']:
        w['classification'].set_text(item['classification'])
    else:
        w['classification'].set_text('')
    if 'studio' in item and item['studio']:
        w['studio'].set_text(item['studio'])
    else:
        w['studio'].set_text('')
    if 'o_site' in item and item['o_site']:
        w['o_site'].set_text(item['o_site'])
    else:
        w['o_site'].set_text('')
    if 'director' in item and item['director']:
        w['director'].set_text(item['director'])
    else:
        w['director'].set_text('')
    if 'site' in item and item['site']:
        w['site'].set_text(item['site'])
    else:
        w['site'].set_text('')
    if 'trailer' in item and item['trailer']:
        w['trailer'].set_text(item['trailer'])
    else:
        w['trailer'].set_text('')
    if 'genre' in item and item['genre']:
        w['genre'].set_text(item['genre'])
    else:
        w['genre'].set_text('')
    if 'color' in item and item['color']:
        w['color'].set_active(gutils.digits_only(item['color'], 3))
    else:
        w['color'].set_active(gutils.digits_only(self.config.get('color', 0, section='defaults'), 3))
    if 'layers' in item and item['layers']:
        w['layers'].set_active(gutils.digits_only(item['layers'], 4))
    else:
        w['layers'].set_active(gutils.digits_only(self.config.get('layers', 0, section='defaults'), 4))
    if 'region' in item and item['region'] >= 0:
            w['region'].set_active(gutils.digits_only(item['region'], 8))
    else:
        w['region'].set_active(gutils.digits_only(self.config.get('region', 0, section='defaults'), 8))
    if 'cond' in item and item['cond'] >= 0:
        w['condition'].set_active(gutils.digits_only(item['cond'], 5))
    else:
        w['condition'].set_active(gutils.digits_only(self.config.get('condition', 0, section='defaults'), 5))
    if 'media_num' in item and item['media_num']:
        w['discs'].set_value(gutils.digits_only(item['media_num']))
    else:
        w['discs'].set_value(1)
    if 'rating' in item and item['rating']:
        w['rating_slider'].set_value(gutils.digits_only(item['rating'], 10))
    else:
        w['rating_slider'].set_value(0)
    if 'seen' in item and item['seen'] is True:
        w['seen'].set_active(True)
    else:
        w['seen'].set_active(False)
    if 'cast' in item and item['cast']:
        cast_buffer.set_text(item['cast'])
    else:
        cast_buffer.set_text('')
    if 'notes' in item and item['notes']:
        notes_buffer.set_text(item['notes'])
    else:
        notes_buffer.set_text('')
    if 'plot' in item and item['plot']:
        plot_buffer.set_text(item['plot'])
    else:
        plot_buffer.set_text('')
    pos = 0
    if 'medium_id' in item and item['medium_id']:
        pos = gutils.findKey(item['medium_id'], self.media_ids)
    else:
        pos = gutils.findKey(int(self.config.get('media', 0, section='defaults')), self.media_ids)
    if pos is not None:
        w['media'].set_active(int(pos))
    else:
        w['media'].set_active(0)
    pos = 0
    if 'vcodec_id' in item and item['vcodec_id']:
        pos = gutils.findKey(item['vcodec_id'], self.vcodecs_ids)
    else:
        pos = gutils.findKey(int(self.config.get('vcodec', 0, section='defaults')), self.vcodecs_ids)
    if pos is not None:
        w['vcodec'].set_active(int(pos))
    else:
        w['vcodec'].set_active(0)
    pos = 0
    if 'volume_id' in item and item['volume_id']:
        pos = gutils.findKey(item['volume_id'], self.volume_combo_ids)
    if pos is not None:
        w['volume'].set_active(int(pos))
    else:
        w['volume'].set_active(0)
    pos = 0
    if 'collection_id' in item and item['collection_id']:
        pos = gutils.findKey(item['collection_id'], self.collection_combo_ids)
    if pos is not None:
        w['collection'].set_active(int(pos))
    else:
        w['collection'].set_active(0)
    # tags
    for tag in self.am_tags:
        self.am_tags[tag].set_active(False)
    if 'tags' in item:
        for tag in item['tags']:
            i = gutils.findKey(tag.tag_id, self.tags_ids)
            self.am_tags[i].set_active(True)
    # languages
    w['lang_treeview'].get_model().clear()
    if 'languages' in item and len(item['languages']) > 0:
        for i in item['languages']:
            self.create_language_row(i)
    # poster
    if 'poster_md5' in item and item['poster_md5']:
        image_path = gutils.get_image_fname(item["poster_md5"], self.db, 'm')
        if not image_path:
            image_path = '' # isfile doesn't like bool
        w['image'].set_text(item['poster_md5'])
    elif 'image' in item and item['image']:
        if len(item['image']) == 32: # md5
            image_path = gutils.get_image_fname(item["image"], self.db, 'm')
            if not image_path:
                image_path = '' # isfile doesn't like bool
            else:
                w['image'].set_text(item['image'])
        else:
            image_path = os.path.join(self.locations['posters'], "m_%s.jpg" % item['image'])
            log.warn("TODO: image=%s", item['image'])
    else:
        w['image'].set_text('')
        image_path = gutils.get_defaultimage_fname(self)
    if not os.path.isfile(image_path):
        image_path = gutils.get_defaultimage_fname(self)
    w['picture'].set_from_file(image_path)

    w['notebook'].set_current_page(0)
    w['o_title'].grab_focus()
Ejemplo n.º 12
0
def clone_movie(self):
    session = self.db.Session()

    if self.selected_iter[0] is None:
        log.warn("cannot clone movie: no item selected")
        return False
    movie = session.query(db.Movie).filter_by(number=self.selected[0]).first()

    if movie is None:
        log.warn("cannot clone movie: Movie(%s) not found", number)
        return False

    next_number = gutils.find_next_available(self.db)

    # integer problem workaround
    if int(movie.seen) == 1:
        seen = True
    else:
        seen = False
    new_movie = db.Movie()

    # TODO: WARNING: loan problems (don't copy volume/collection data until resolved)
    new_movie.cast = movie.cast
    new_movie.classification = movie.classification
    new_movie.vcodec_id = movie.vcodec_id
    new_movie.barcode = movie.barcode
    new_movie.cameraman = movie.cameraman
    new_movie.collection_id = movie.collection_id
    new_movie.volume_id = movie.volume_id
    new_movie.color = movie.color
    new_movie.cond = movie.cond
    new_movie.country = movie.country
    new_movie.director = movie.director
    new_movie.genre = movie.genre
    new_movie.site = movie.site
    new_movie.loaned = movie.loaned
    new_movie.layers = movie.layers
    new_movie.medium_id = movie.medium_id
    new_movie.number = next_number
    new_movie.media_num = movie.media_num
    new_movie.notes = movie.notes
    new_movie.o_title = movie.o_title
    new_movie.plot = movie.plot
    new_movie.poster_md5 = movie.poster_md5
    new_movie.ratio_id = movie.ratio_id
    new_movie.rating = movie.rating
    new_movie.region = movie.region
    new_movie.runtime = movie.runtime
    new_movie.resolution = movie.resolution
    new_movie.screenplay = movie.screenplay
    new_movie.seen = seen
    new_movie.o_site = movie.o_site
    new_movie.studio = movie.studio
    new_movie.title = movie.title
    new_movie.trailer = movie.trailer
    new_movie.year = movie.year

    new_movie.tags = movie.tags
    new_movie.languages = movie.languages
    new_movie.loans = movie.loans

    # save
    session.add(new_movie)
    if not commit(session):
        return False

    if movie.poster_md5:
        image_path = gutils.get_image_fname(movie.poster_md5, self.db)
        if not image_path or not os.path.isfile(image_path):
            image_path = gutils.get_defaultimage_fname(self)
        handler = self.Image.set_from_file(image_path)

    # change_filter calls populate_treeview which updates the status bar
    quick_filter.change_filter(self)
Ejemplo n.º 13
0
def set_details(self, item=None):  #{{{
    if item is None:
        item = {}
    if 'movie_id' in item and item['movie_id']:
        self._am_movie_id = item['movie_id']
    else:
        self._am_movie_id = None
    w = self.widgets['add']

    cast_buffer = w['cast'].get_buffer()
    notes_buffer = w['notes'].get_buffer()
    plot_buffer = w['plot'].get_buffer()

    if 'o_title' in item and item['o_title']:
        w['o_title'].set_text(item['o_title'])
    else:
        w['o_title'].set_text('')
    if 'title' in item and item['title']:
        w['title'].set_text(item['title'])
    else:
        w['title'].set_text('')
    if 'number' in item and item['number']:
        w['number'].set_value(int(item['number']))
    else:
        w['number'].set_value(int(gutils.find_next_available(self.db)))
    if 'title' in item and item['title']:
        w['title'].set_text(item['title'])
    if 'year' in item and item['year']:
        w['year'].set_value(gutils.digits_only(item['year'], 2100))
    else:
        w['year'].set_value(0)
    if 'resolution' in item and item['resolution']:
        if self.config.get('use_resolution_alias', True):
            w['resolution'].get_child().set_text(item['resolution'])
        elif 'height' in item and item['height'] and 'width' in item and item[
                'width']:
            w['resolution'].get_child().set_text(
                "%dx%d" % (item['width'], item['height']))
        else:  # failback to 'resolution'
            w['resolution'].get_child().set_text(item['resolution'])
    else:
        w['resolution'].get_child().set_text('')
    if 'runtime' in item and item['runtime']:
        w['runtime'].set_value(gutils.digits_only(item['runtime']))
    else:
        w['runtime'].set_value(0)
    if 'barcode' in item and item['barcode']:
        w['barcode'].set_text(item['barcode'])
    else:
        w['barcode'].set_text('')
    if 'cameraman' in item and item['cameraman']:
        w['cameraman'].set_text(item['cameraman'])
    else:
        w['cameraman'].set_text('')
    if 'screenplay' in item and item['screenplay']:
        w['screenplay'].set_text(item['screenplay'])
    else:
        w['screenplay'].set_text('')
    if 'country' in item and item['country']:
        w['country'].set_text(item['country'])
    else:
        w['country'].set_text('')
    if 'classification' in item and item['classification']:
        w['classification'].set_text(item['classification'])
    else:
        w['classification'].set_text('')
    if 'studio' in item and item['studio']:
        w['studio'].set_text(item['studio'])
    else:
        w['studio'].set_text('')
    if 'o_site' in item and item['o_site']:
        w['o_site'].set_text(item['o_site'])
    else:
        w['o_site'].set_text('')
    if 'director' in item and item['director']:
        w['director'].set_text(item['director'])
    else:
        w['director'].set_text('')
    if 'site' in item and item['site']:
        w['site'].set_text(item['site'])
    else:
        w['site'].set_text('')
    if 'trailer' in item and item['trailer']:
        w['trailer'].set_text(item['trailer'])
    else:
        w['trailer'].set_text('')
    if 'genre' in item and item['genre']:
        w['genre'].set_text(item['genre'])
    else:
        w['genre'].set_text('')
    if 'color' in item and item['color']:
        w['color'].set_active(gutils.digits_only(item['color'], 3))
    else:
        w['color'].set_active(
            gutils.digits_only(self.config.get('color', 0, section='defaults'),
                               3))
    if 'layers' in item and item['layers']:
        w['layers'].set_active(gutils.digits_only(item['layers'], 4))
    else:
        w['layers'].set_active(
            gutils.digits_only(
                self.config.get('layers', 0, section='defaults'), 4))
    if 'region' in item and item['region'] >= 0:
        w['region'].set_active(gutils.digits_only(item['region'], 11))
    else:
        w['region'].set_active(
            gutils.digits_only(
                self.config.get('region', 0, section='defaults'), 11))
    if 'cond' in item and item['cond'] >= 0:
        w['condition'].set_active(gutils.digits_only(item['cond'], 5))
    else:
        w['condition'].set_active(
            gutils.digits_only(
                self.config.get('condition', 0, section='defaults'), 5))
    if 'media_num' in item and item['media_num']:
        w['discs'].set_value(gutils.digits_only(item['media_num']))
    else:
        w['discs'].set_value(1)
    if 'rating' in item and item['rating']:
        w['rating_slider'].set_value(gutils.digits_only(item['rating'], 10))
    else:
        w['rating_slider'].set_value(0)
    if 'seen' in item:
        if item['seen'] is True:
            w['seen'].set_active(True)
        else:
            w['seen'].set_active(False)
    else:
        w['seen'].set_active(
            bool(self.config.get('seen', True, section='defaults')))
    if 'cast' in item and item['cast']:
        cast_buffer.set_text(item['cast'])
    else:
        cast_buffer.set_text('')
    if 'notes' in item and item['notes']:
        notes_buffer.set_text(item['notes'])
    else:
        notes_buffer.set_text('')
    if 'plot' in item and item['plot']:
        plot_buffer.set_text(item['plot'])
    else:
        plot_buffer.set_text('')
    pos = 0
    if 'medium_id' in item and item['medium_id']:
        pos = gutils.findKey(item['medium_id'], self.media_ids)
    else:
        pos = gutils.findKey(
            int(self.config.get('media', 0, section='defaults')),
            self.media_ids)
    if pos is not None:
        w['media'].set_active(int(pos))
    else:
        w['media'].set_active(0)
    pos = 0
    if 'vcodec_id' in item and item['vcodec_id']:
        pos = gutils.findKey(item['vcodec_id'], self.vcodecs_ids)
    else:
        pos = gutils.findKey(
            int(self.config.get('vcodec', 0, section='defaults')),
            self.vcodecs_ids)
    if pos is not None:
        w['vcodec'].set_active(int(pos))
    else:
        w['vcodec'].set_active(0)
    pos = 0
    if 'volume_id' in item and item['volume_id']:
        pos = gutils.findKey(item['volume_id'], self.volume_combo_ids)
    if pos is not None:
        w['volume'].set_active(int(pos))
    else:
        w['volume'].set_active(0)
    pos = 0
    if 'collection_id' in item and item['collection_id']:
        pos = gutils.findKey(item['collection_id'], self.collection_combo_ids)
    if pos is not None:
        w['collection'].set_active(int(pos))
    else:
        w['collection'].set_active(0)
    # tags
    for tag in self.am_tags:
        self.am_tags[tag].set_active(False)
    if 'tags' in item:
        for tag in item['tags']:
            i = gutils.findKey(tag.tag_id, self.tags_ids)
            self.am_tags[i].set_active(True)
    # languages
    w['lang_treeview'].get_model().clear()
    if 'languages' in item and len(item['languages']) > 0:
        for i in item['languages']:
            self.create_language_row(i)
    # poster
    w['aremove_poster'].set_sensitive(True)
    if 'poster_md5' in item and item['poster_md5']:
        image_path = gutils.get_image_fname(item["poster_md5"], self.db, 'm')
        if not image_path:
            image_path = ''  # isfile doesn't like bool
            w['aremove_poster'].set_sensitive(False)
        w['image'].set_text(item['poster_md5'])
    elif 'image' in item and item['image']:
        if len(item['image']) == 32:  # md5
            image_path = gutils.get_image_fname(item["image"], self.db, 'm')
            if not image_path:
                image_path = ''  # isfile doesn't like bool
                w['aremove_poster'].set_sensitive(False)
            else:
                w['image'].set_text(item['image'])
        else:
            image_path = os.path.join(self.locations['posters'],
                                      "m_%s.jpg" % item['image'])
            log.warn("TODO: image=%s", item['image'])
    else:
        w['image'].set_text('')
        image_path = gutils.get_defaultimage_fname(self)
        w['aremove_poster'].set_sensitive(False)
    if not os.path.isfile(image_path):
        image_path = gutils.get_defaultimage_fname(self)
        w['aremove_poster'].set_sensitive(False)
    w['picture'].set_from_file(image_path)

    w['notebook'].set_current_page(0)
    w['o_title'].grab_focus()
Ejemplo n.º 14
0
def clone_movie(self):
	treeselection = self.widgets['treeview'].get_selection()
	(tmp_model, tmp_iter) = treeselection.get_selected()
	if tmp_iter is None:
		return False
	number = tmp_model.get_value(tmp_iter, 0)
	movie = self.db.Movie.get_by(number=number)

	if movie is None:
		return False

	next_number = gutils.find_next_available(self.db)
	new_image = str(movie.image) + '_' + str(next_number)
	
	# integer problem workaround
	if int(movie.seen)==1:
		seen = True
	else:
		seen = False
	new_movie = self.db.Movie()
	
	new_movie.cast = movie.cast
	new_movie.classification = movie.classification
	new_movie.color = movie.color
	new_movie.cond = movie.cond
	new_movie.country = movie.country
	new_movie.director = movie.director
	new_movie.genre = movie.genre
	new_movie.image = new_image
	new_movie.site = movie.site
	new_movie.layers = movie.layers
	new_movie.medium_id = movie.medium_id
	new_movie.number = next_number
	new_movie.media_num = movie.media_num
	new_movie.notes = movie.notes
	new_movie.o_title = movie.o_title
	new_movie.plot = movie.plot
	new_movie.rating = movie.rating
	new_movie.region = movie.region
	new_movie.runtime = movie.runtime
	new_movie.seen = seen
	new_movie.o_site = movie.o_site
	new_movie.studio = movie.studio
	new_movie.title = movie.title
	new_movie.trailer = movie.trailer
	new_movie.year = movie.year
	
	new_movie.tags = movie.tags
	new_movie.languages = movie.languages
	
	# save
	new_movie.save()
	new_movie.flush()

	# WARNING: loan problems (don't copy volume/collection data until resolved)

	tmp_dest = self.locations['posters']
	if movie.image is not None:
		image_path = os.path.join(tmp_dest, str(movie.image)+".jpg")
		clone_path = os.path.join(tmp_dest, new_image+".jpg")
		# clone image
		shutil.copyfile(image_path, clone_path)
		image_path = clone_path
		gutils.make_thumbnail(self, "%s.jpg" % new_image)
		gutils.make_medium_image(self, "%s.jpg" % new_image)
	else:
		image_path = os.path.join(self.locations['images'], "default.png")
	handler = self.Image.set_from_file(image_path)

	#update statusbar
	self.total = self.total + 1
	self.count_statusbar()
	self.populate_treeview()
	#self.widgets['treeview'].set_cursor(next_number-1)
	self.go_last()
	self.treeview_clicked()
Ejemplo n.º 15
0
def clone_movie(self):
	treeselection = self.main_treeview.get_selection()
	(tmp_model, tmp_iter) = treeselection.get_selected()	
	m_id = tmp_model.get_value(tmp_iter, 1)
	movie_id = self.db.get_value(field="id", table="movies", where="number='%s'"%m_id)
	
	if movie_id == None:
		return false
		
	row = self.db.select_movie_by_num(m_id)[0]
	next_number = gutils.find_next_available(self)
	new_image = str(row['image']) + '_' + str(next_number)
	self.db.cursor.execute(
		"""INSERT INTO 'movies' ('id','original_title','title','director','plot','image',
			'year','runtime','actors','country','genre','media','classification','studio',
			'site','color','region','layers','condition','imdb','trailer','obs','num_media',
			'rating','loaned','seen','number')
		VALUES (Null,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',
			'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','0','%s','%s')""" % \
		(gutils.gescape(str(row['original_title'])), \
		gutils.gescape(str(row['title'])), \
		gutils.gescape(str(row['director'])), \
		gutils.gescape(str(row['plot'])), \
		gutils.gescape(new_image), \
		gutils.gescape(str(row['year'])), \
		gutils.gescape(str(row['runtime'])), \
		gutils.gescape(str(row['actors'])), \
		gutils.gescape(str(row['country'])), \
		gutils.gescape(str(row['genre'])), \
		gutils.gescape(str(row['media'])), \
		gutils.gescape(str(row['classification'])), \
		gutils.gescape(str(row['studio'])), \
		gutils.gescape(str(row['site'])), \
		gutils.gescape(str(row['color'])), \
		gutils.gescape(str(row['region'])), \
		gutils.gescape(str(row['layers'])), \
		gutils.gescape(str(row['condition'])), \
		gutils.gescape(str(row['imdb'])), \
		gutils.gescape(str(row['trailer'])), \
		gutils.gescape(str(row['obs'])), \
		str(row['num_media']), \
		str(row['rating']), \
		str(row['seen']), \
		str(next_number) )\
	) # dont copy volume/collection data (loan problems)
	next_movie_id = self.db.get_value(field="id", table="movies", where="number='%s'"%next_number)
	# tags
	for item in self.db.get_all_data(table_name="movie_tag",what="tag_id", where="movie_id='%s'"%movie_id):
		self.db.cursor.execute("""
			INSERT INTO movie_tag('movie_id','tag_id') VALUES('%s','%s')""" % \
				(next_movie_id, item['tag_id']))
	# languages
	for item in self.db.get_all_data(table_name="movie_lang",what="lang_id, type", where="movie_id='%s'"%movie_id):
		self.db.cursor.execute("""
			INSERT INTO movie_lang('movie_id','lang_id', 'type')
				VALUES('%s','%s', '%s')""" % \
			(next_movie_id, item['lang_id'], item['type']))
	tmp_dest = os.path.join(self.griffith_dir, "posters")
	if str(str(row['image'])) != '':
		image_path = os.path.join(tmp_dest, str(row['image'])+".jpg")
		clone_path = os.path.join(tmp_dest, new_image+".jpg")
		# clone image
		shutil.copyfile(image_path, clone_path)
		image_path = clone_path
	else:
		if self.windows:
			image_path = "images/default.png"
		else:
			image_path = os.path.join(self.locations['images'], "default.png")
	handler = self.Image.set_from_file(image_path)
		
	#update statusbar
	self.total = self.total + 1
	self.total_filter = self.total
	self.count_statusbar()
	self.populate_treeview(self.db.get_all_data(order_by="number ASC"))
	self.main_treeview.set_cursor(next_number-1)
	self.treeview_clicked()