def GenerateFullPreview(mapObject, userObject): currentDirectory = os.getcwd() + os.sep os.chdir(settings.OPENRA_PATH) path = currentDirectory + 'openraData/data/maps/' + str(mapObject.id) + os.sep filename = "" Dir = os.listdir(path) for fn in Dir: if fn.endswith('.oramap'): filename = fn break if filename == "": os.chdir(currentDirectory) return False command = 'mono --debug OpenRA.Utility.exe %s --full-preview %s' % (mapObject.game_mod, path + filename) proc = Popen(command.split(), stdout=PIPE).communicate() try: shutil.move(settings.OPENRA_PATH + os.path.splitext(filename)[0] + ".png", path + os.path.splitext(filename)[0] + "-full.png") transac = Screenshots( user = userObject, ex_id = mapObject.id, ex_name = "maps", posted = timezone.now(), map_preview = True, ) transac.save() os.chdir(currentDirectory) return True except: os.chdir(currentDirectory) return False
def addScreenshot(f, arg, user_id, item): if item == 'map': Object = Maps.objects.filter(id=arg) if not Object: return False if not (Object[0].user_id == user_id.id or user_id.is_superuser): return False else: return False tempname = '/tmp/screenshot.temp' with open(tempname, 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk) command = 'file -b --mime-type %s' % tempname proc = Popen(command.split(), stdout=PIPE).communicate() mimetype = proc[0].strip() if mimetype not in ['image/jpeg','image/png','image/gif']: return False userObject = User.objects.get(pk=Object[0].user_id) transac = Screenshots( user = userObject, ex_id = int(arg), ex_name = item+"s", posted = timezone.now(), map_preview = False, ) transac.save() path = os.getcwd() + os.sep + __name__.split('.')[0] + '/data/screenshots/' + str(transac.id) + '/' if not os.path.exists(path): os.makedirs(path) shutil.move(tempname, path + arg + "." + mimetype.split('/')[1]) command = 'identify -format "%w,%h" {0}'.format(path + arg + "." + mimetype.split('/')[1]) proc = Popen(command.split(), stdout=PIPE).communicate() details = proc[0].strip().strip('"').split(',') im = Image(Blob(open(path + arg + "." + mimetype.split('/')[1]).read()), Geometry(int(details[0]),int(details[1]))) scaleH = int(details[0]) / 100.0 scaleH = 250 / scaleH scaleH = int(details[1]) / 100.0 * scaleH im.quality(100) im.filterType(FilterTypes.SincFilter) im.scale('250x%s' % scaleH) im.sharpen(1.0) im.write(str(path + arg + "-mini." + mimetype.split('/')[1]))
def GenerateFullPreview(self, userObject): os.chdir(settings.OPENRA_PATH) command = 'mono --debug OpenRA.Utility.exe %s--full-preview %s' % (self.MapMod, self.map_full_path_filename) proc = Popen(command.split(), stdout=PIPE).communicate() try: shutil.move(misc.addSlash(settings.OPENRA_PATH) + self.preview_filename, self.map_full_path_directory + os.path.splitext(self.preview_filename)[0] + "-full.png") self.flushLog(proc) self.fullpreview_generated = True transac = Screenshots( user = userObject, ex_id = int(self.UID), ex_name = "maps", posted = timezone.now(), map_preview = True, ) transac.save() except: self.flushLog( ["Failed to generate fullpreview for this file."] ) os.chdir(self.currentDirectory)