Форум сайта python.su
import os from jinja2 import Environment, FileSystemLoader class SiteViews(): def indexView(self): TEMPLATE_DIR = './template/' html = Environment(loader=FileSystemLoader(TEMPLATE_DIR), trim_blocks=True) return html.get_template('template.html').render(title = 'Title', test = 'Test')
elif environ['PATH_INFO'] == '/map': status = '200 OK' templ = SiteViews() #output = templ.indexView() response_headers = [('Content-type', 'html; charset=UTF-8')] start_response(status, response_headers) return templ.indexView()
# Philippe HUBERDEAU (philpma@free.fr) # # Python script to create windows Batch file to launch Nuke renders by command line. It's less memory consuming # Plus some options like : # render "frame by frame" which allows to flush properly the memory for each frame. Some comps (same thing with Eyeon Fusion) tends to increase rendering time all along the process. # "skip existing frame" for deleted bug frames or deleted modified frames to avoid complicated frameranges. # These scripts are inspired from Tim BOWMAN's "bgNukes" and Jep HILL's "skip existing renders" scripts . # # From Python import os, sys, shutil, string import subprocess # From Nuke import nuke, nukescripts if __name__ == "__main__": if len ( sys.argv ) != 5: print 'Usage: NUKE renderWskipExistingFrame.py <nuke_script> <write name> <frame number> <views>' sys.exit(-1) comp = sys.argv[1] write = sys.argv[2] framenum = sys.argv[3] views = sys.argv[4] nuke.scriptOpen( comp ) filepath = nuke.toNode(write)['file'].value() padding = int(filepath.split("%0")[1][0]) for i in range(padding-len(framenum)): framenum = "0" + framenum for view in views.split(","): image = (filepath.replace("%04d", framenum)).replace("%V", view).replace("%v", view) tmpImage = image + ".tmp" if not (os.path.exists(image) or os.path.exists(tmpImage)): print image + " doesn't exist so rendering this frame.........................................................." nuke.execute( write, int(framenum), int(framenum), 1, [view]) else: print "\n" print image + " : already exists ... skipping..." def CLrender(nodes=[]): """ Creates command-line Nuke batch file with different control parameters (frame by frame, skip existing frame, Stereo) """ if nuke.root().knob('name').value() == '': nuke.message('This script is not named. Please save it and try again.') return nodelist = '' if nodes != []: nodelist = ','.join([n.name() for n in nodes if n.Class() == "Write"]) else: Writes = nuke.allNodes("Write") if len(Writes)==1: nodelist = Writes[0].name() if nodelist == "": nuke.message("Please select Write node(s) !") return class CLrenderDialog(nukescripts.PythonPanel): def __init__(self): nukescripts.PythonPanel.__init__(self, 'Create rendering command line batch file(s) -- (philhub 2011)') self.setMinimumSize(600, 300) self.nodesKnob = nuke.String_Knob('nodesExec', 'Node(s) to execute:', nodelist) self.addKnob(self.nodesKnob) self.startKnob = nuke.Int_Knob('startFrame', 'Start frame :') self.addKnob(self.startKnob) self.endKnob = nuke.Int_Knob('endFrame', ' End frame :') self.addKnob(self.endKnob) self.endKnob.clearFlag(nuke.STARTLINE) self.spaceKnob = nuke.Text_Knob('space', '') self.addKnob(self.spaceKnob) self.spaceKnob.setFlag(nuke.STARTLINE) self.limitKnob = nuke.Boolean_Knob('limit', 'Limit Memory to (Go)') self.addKnob(self.limitKnob) self.limitKnob.setFlag(nuke.STARTLINE) self.memKnob = nuke.Int_Knob('mem', '') self.addKnob(self.memKnob) self.memKnob.clearFlag(nuke.STARTLINE) # self.unitKnob = nuke.Text_Knob('unit', 'Go') # self.addKnob(self.unitKnob) # self.unitKnob.clearFlag(nuke.STARTLINE) self.limitcpuKnob = nuke.Boolean_Knob('limitcpu', 'Limit Cores to') self.addKnob(self.limitcpuKnob) self.limitcpuKnob.clearFlag(nuke.STARTLINE) self.cpuKnob = nuke.Int_Knob('cpu', '') self.addKnob(self.cpuKnob) self.cpuKnob.clearFlag(nuke.STARTLINE) self.spaceKnob2 = nuke.Text_Knob('space2', '') self.addKnob(self.spaceKnob2) self.spaceKnob2.setFlag(nuke.STARTLINE) self.threadsKnob = nuke.Int_Knob('threads', 'Number of BAT files :') self.addKnob(self.threadsKnob) self.threadsKnob.setFlag(nuke.STARTLINE) self.threadWhyKnob = nuke.Text_Knob('threadWhy', '(to distrib on multiple cores/boxes)') self.addKnob(self.threadWhyKnob) self.threadWhyKnob.clearFlag(nuke.STARTLINE) self.fbfKnob = nuke.Boolean_Knob('fbf', 'Frame by Frame') self.addKnob(self.fbfKnob) self.fbfKnob.setFlag(nuke.STARTLINE) self.skipKnob = nuke.Boolean_Knob('skip', 'Skip existing Frames') self.addKnob(self.skipKnob) self.skipKnob.setFlag(nuke.STARTLINE) self.stereoKnob = nuke.Boolean_Knob('stereo', 'Stereo') self.addKnob(self.stereoKnob) self.stereoKnob.setFlag(nuke.STARTLINE) self.backupKnob = nuke.Boolean_Knob('backup', "Create a comp's backup") self.addKnob(self.backupKnob) self.openFolderKnob = nuke.Boolean_Knob('openFolder', "Open folder") self.addKnob(self.openFolderKnob) self.openFolderKnob.setFlag(nuke.STARTLINE) self.spaceKnob2 = nuke.Text_Knob('space', '') self.addKnob(self.spaceKnob2) self.spaceKnob2.setFlag(nuke.STARTLINE) self.backupKnob.setFlag(nuke.STARTLINE) self.okButton = nuke.Script_Knob( "OK" ) self.addKnob( self.okButton ) self.okButton.setFlag(nuke.STARTLINE) self.cancelButton = nuke.Script_Knob( "Cancel" ) self.addKnob( self.cancelButton ) self.infosKnob = nuke.PyScript_Knob('infos', "infos") self.infosKnob.setCommand('''import webbrowser webbrowser.open("http://www.nukepedia.com/python/render/cmdlinerender/")''') self.addKnob(self.infosKnob) p = CLrenderDialog() p.startKnob.setValue(int(nuke.knob("first_frame"))) p.endKnob.setValue(int(nuke.knob("last_frame"))) p.memKnob.setValue(8) p.cpuKnob.setValue(2) p.threadsKnob.setValue(6) p.fbfKnob.setValue(1) p.skipKnob.setValue(0) p.stereoKnob.setValue(0) p.backupKnob.setValue(0) p.openFolderKnob.setValue(1) result = p.showModalDialog() if not result: return nuke.scriptSave('') start = p.startKnob.value() end = p.endKnob.value() threads = p.threadsKnob.value() mem = p.memKnob.value() cpu = p.cpuKnob.value() fbf = p.fbfKnob.value() skip = p.skipKnob.value() stereo = p.stereoKnob.value() if threads < 1: return flags = "-x " if stereo: views = ','.join(nuke.views()) else: views = nuke.views()[0] flags += " -view " + views if nodelist != '': flags += " -X " + nodelist if p.limitKnob.value(): flags += " -c " + str(mem) + "G" if p.limitcpuKnob.value(): flags += " -m " + str(cpu) comp_dirpath = nuke.value("root.name") exe = '"'+nuke.env['ExecutablePath']+'"' # for BAT file, " avoid error with names with spaces if p.backupKnob.value(): bkp_dirpath = os.path.dirname(comp_dirpath) + '/backup_from_CLrender/' if not os.path.exists(bkp_dirpath): os.makedirs(bkp_dirpath) bkp_filepath = bkp_dirpath + os.path.basename(comp_dirpath) shutil.copy(comp_dirpath, bkp_filepath) comp_dirpath = '"' + bkp_filepath + '"' # for BAT file, " avoid error with names with spaces else: comp_dirpath = '"' + comp_dirpath + '"' # for BAT file, " avoid error with names with spaces for thread in range(threads): bat_name = nuke.value("root.name").replace('.nk', '_' + nodelist.replace(",","-") + "_x"+ str(threads) + "x" + str(start+ thread) + "-" + str(end)+ '.bat') if fbf and not(skip): cmd = r"FOR /l %%I IN (" + ",".join([str(start + thread), str(threads), str(end)]) + r") DO (" + " ".join([exe, flags, r"-F %%I-%%I", comp_dirpath]) + ")" bat_name = bat_name.replace('.bat', '_FrameByFrame.bat') elif skip: cmd = r"FOR /l %%I IN (" + ",".join([str(start + thread), str(threads), str(end)]) + r") DO (" + " ".join([exe, "-t", os.path.realpath( __file__ ), comp_dirpath, nodelist, "%%I", views]) + ")" bat_name = bat_name.replace('.bat', '_SkipExisting.bat') else: cmd = " ".join([exe, flags, '-F', '"' + str(start+ thread) + "-" + str(end) + 'x' + str(threads) + '"', comp_dirpath ]) if stereo: bat_name = bat_name.replace('.bat', '_STEREO.bat') print "command : " + cmd print "saved to : " + bat_name try: file = open(bat_name, 'w') #file.write("mode con cols=500 lines=500") file.write("\nCOLOR 4f\n") file.write("\n") file.write(cmd) file.write("\n\nCOLOR 2f\n") file.write("taskkill cmd.exe") finally: file.close() if p.openFolderKnob.value(): openCompFolder() def openCompFolder(): path = nuke.tcl("return [file dirname [value root.name]]") cmd = "explorer " + (path.replace("//","/")).replace("/","\\") os.system(cmd) ''' menubar = nuke.menu('Nuke') m = menubar.addMenu('Nukepedia') m.addCommand('CL Render', 'CmdLineRender.CLrender(nuke.selectedNodes())') '''
import Image class PreImage(object): ''' input_image - buffer for input image width, height - sizes of input image output_color_space - buffer for image which contain some color space RGB2YCbCr() - function for convert RGB into YCbCr convert() - function for convert from one color space to another ''' def __init__(self, input_image_name): self.input_image = Image.open(input_image_name) self.width, self.height = self.input_image.size size = self.input_image.size self.output_color_space = Image.new("RGB", size) self.output_grey_scale = Image.new("RGB", size) def RGB2YCbCr(self,rgb): cbcr = [0,0,0] cbcr[0] = int(0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]) # Y cbcr[1] = int((rgb[2] - cbcr[0])*0.564 + 128) # Cb cbcr[2] = int((rgb[0] - cbcr[0])*0.713 + 128) # Cr return cbcr def convert(self): cbcr = [0,0,0] for i in range(self.height): for j in range(self.width): rgb = self.input_image.getpixel((j, i)) cbcr = self.RGBYCbCr(rgb) self.output_color_space.putpixel((j, i), tuple(cbcr)) self.output_color_space.save("Result.jpg", "JPEG") a = PreImage("RGB.jpg") a.convert()
from subprocess import Popen import Image Popen(['convert', '-colorspace', 'YCbCr', '-sampling-factor', '4:2:2', 'Test.png', 'Test1.png']).wait()
result = self.l.search_s("OU=Managers"+",DC=domain,DC=loc", ldap.SCOPE_SUBTREE, '(&(objectCategory=Person)(objectClass=user))')
def forward(src, dest): try: data = src.recv(10) while data: dest.sendall(data) data = src.recv(10) except: src.close() dest.close() while True: insock, addr_info = sock.accept() print 'start proxy session with client', addr_info[0] # ... handshake # ... получение ip и port # ... коннект к ip:port -> outsock Thread(target=forward, args=(insock, outsock)).start() Thread(target=forward, args=(outsock, insock)).start()
cur = conn.cursor() cur.execute('SELECT * FROM name WHERE lastname='user' ) row = cur.fetchone() while row: print "(row[0]) row = cur.fetchone()
return HttpResponseRedirect(u'success_%s' % main_url)
CSRF verification failed. Request aborted
class Category(models.Model): name = models.CharField(...) class Post = (models.Model): name = models.CharField(...) category = models.ForeqignKey(Category, null=True, blank=True) all_posts = Post.objects.values('name', 'category__name')
python graphics.py libGL error: failed to load driver: swrast libGL error: Try again with LIBGL_DEBUG=verbose for more details. Traceback (most recent call last): File "graphics.py", line 50, in <module> from pyglet.gl import * File "/home/svitaliy/Документы/src_python/pyglet/gl/__init__.py", line 510, in <module> import pyglet.window File "/home/svitaliy/Документы/src_python/pyglet/window/__init__.py", line 1684, in <module> gl._create_shadow_window() File "/home/svitaliy/Документы/src_python/pyglet/gl/__init__.py", line 494, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "/home/svitaliy/Документы/src_python/pyglet/window/xlib/__init__.py", line 474, in __init__ super(XlibWindow, self).__init__(*args, **kwargs) File "/home/svitaliy/Документы/src_python/pyglet/window/__init__.py", line 641, in __init__ raise NoSuchConfigException('No standard config is available.')
message = request.args['mess'] for line in message: line = line.split() for n in line: arr_info.append(message) if request.args != None: name = request.args['user'] for i in arr: arr.append(name) for i in range(len(arr)): m = re.search(u'что-то регулярное', arr[i]) if m != None:
import math import time #Import DirectPython modules and constants. import d3d11 import d3d11x from d3d11c import * #First we need a window. If you don't want to do any visible #rendering this could be omitted. window = d3d11.Window() window.setTitle("Tutorial 2 - A colored triangle") window.show(SW_SHOW) #Then create a Device and tell it to use our window for drawing. #Use a software WARP-device, in real applications you might #try hardware first and fall back to software if that fails. device = d3d11.Device(window, DRIVER_TYPE_WARP) #Our vertex layout description: position (x, y, z) and color (r, g, b, a). #See the "Layouts and input layouts" article in the documentation. vertexDesc = [ ("POSITION", 0, FORMAT_R32G32B32_FLOAT, 0, 0, INPUT_PER_VERTEX_DATA, 0), ("COLOR", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0), #This is functionally same as above, only easier to read. I use the complex one now #so that you don't get confused when you encounter it in samples. #("POSITION", 0, FORMAT_R32G32B32_FLOAT), #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT), ] #Our triangle - three vertices with position and color. The layout must match 'vertexDesc'. triangle = [ (-5, 0, 0) + (1, 0, 0, 1), #Red vertex. (0, 10, 0) + (0, 1, 0, 1), #Green vertex. (5, 0, 0) + (0, 0, 1, 1), #Blue vertex. ] #Effect for rendering. The file contains trivial vertex- and pixel-shader. effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Tutorial2.fx")) #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or #the pass's input signature is compatible with that combination. inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0) #Create a hardware buffer to hold our triangle. vertexBuffer = d3d11.Buffer(vertexDesc, triangle, BIND_VERTEX_BUFFER) #Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up. viewMatrix = d3d11.Matrix() viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0)) def mainloop(): while 1: #Check all new messages. for msg in window.getMessages(): if msg.code == WM_DESTROY: #Close the application. return #Set default render targets. device.setRenderTargetsDefault() # <--------------- ВОТ #Set vertex buffer, input layout and topology. device.setVertexBuffers([vertexBuffer]) device.setInputLayout(inputLayout) device.setPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLELIST) #Projection matrix. screenDesc = device.getScreenDesc() fieldOfView = math.radians(60.0) #60 degrees. aspectRatio = float(screenDesc.width) / screenDesc.height projMatrix = d3d11.Matrix() projMatrix.perspectiveFov(fieldOfView, aspectRatio, 0.1, 100.0) #The world matrix. Rotate the triangle (in radians) based #on the value returned by clock(). yRot = time.clock() worldMatrix = d3d11.Matrix() worldMatrix.rotate((0, yRot, 0)) #Combine matrices into one matrix by multiplying them. wordViewProj = worldMatrix * viewMatrix * projMatrix #Update effect variable(s). effect.set("worldViewProjection", wordViewProj) #Apply technique number 0 and it's pass 0. effect.apply(0, 0) #Draw all three vertices using the currently bound vertex buffer #and other settings (Effect, input layout, topology etc.). device.draw(len(vertexBuffer), 0) #Present our rendering. Wait for vsync. device.present(1) #Start the mainloop. mainloop()
rt = device.getDefaultRTView() #Render target rt.clearRenderTarget() ds = device.getDefaultDSView() #Depth stencil ds.clearDepthStencil() device.setRenderTargets([rt], ds) #Must be released. ds.release() rt.release()
device.setRenderTargets([rt], ds)
#!/usr/bin/env python # -*- coding: utf-8 -*- #import sys from gi.repository import Gtk class Handler: def f_open(self, widget, data=None): self.window2 = builder.get_object("window2") self.window2.show_all() self.window2.set_title("Дочернее окно") def close(self, *args): Gtk.main_quit(*args) def close_win(self, *args): # закрываю дочернее окно self.window2.destroy() builder = Gtk.Builder() builder.add_from_file("project-test.glade") builder.connect_signals(Handler()) window = builder.get_object("window1") window.show_all() window.set_title("Основное окно") Gtk.main()
Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: HOST-RESOURCES-MIB::hrProcessorLoad.1
import subprocess cpu_mib = [".1.3.6.1.2.1.25.3.3.1.2.1", ".1.3.6.1.2.1.25.3.3.1.2.2", ".1.3.6.1.2.1.25.3.3.1.2.3", ".1.3.6.1.2.1.25.3.3.1.2.4", ".1.3.6.1.2.1.25.3.3.1.2.5", ".1.3.6.1.2.1.25.3.3.1.2.6", ".1.3.6.1.2.1.25.3.3.1.2.7", ".1.3.6.1.2.1.25.3.3.1.2.8", ".1.3.6.1.2.1.25.3.3.1.2.9", ".1.3.6.1.2.1.25.3.3.1.2.10", ".1.3.6.1.2.1.25.3.3.1.2.11"] for cpu_i in cpu_mib: cpu = subprocess.Popen([r"C:\usr\bin\snmpget.exe","-v","2c","-c","porno","-Oqv","-Ln", "localhost", cpu_i], shell=False, stdout=subprocess.PIPE).communicate()[0].replace('\r', '').replace('\n', '') exit