def main(incoming_args): backendName = os.path.basename(incoming_args[0]) destination = getDestination() logFile = os.path.join(destination, backendName) + ".log" if len(incoming_args) == 1: logger("direct %s \"Unknown\" \"Save to PDF\"\n" % backendName, None) sys.stdout.flush() sys.exit(0) if len(incoming_args) not in (6,7): sys.stdout.flush() logger("Wrong number of arguments. Usage: %s job-id user title copies options [file]\n" % backendName, None) sys.exit(1) global user jobID, user, title, copies, options = (incoming_args[1:6]) outFilename = os.path.join(destination, title) outFilename = os.path.splitext(outFilename)[0] logger(jobID+"\n", logFile) logger(user+"\n", logFile) logger(title+"\n", logFile) logger(copies+"\n", logFile) logger(options+"\n", logFile) # If 5 arguments, take PDF/PS file from stdin; if 6, take filename. if len(incoming_args) == 7: inFilename = incoming_args[6] fileRef = open(inFilename, 'r') fileType = fileRef.read(4) outFilename += getType(fileType) pdfURL = NSURL.fileURLWithPath_(inFilename) pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL) encrypt(inFilename, pdfDoc) os.rename(inFilename, outFilename) else: fileType = sys.stdin.read(4) outFilename += getType(fileType) global myDataObject myDataObject = NSMutableData.alloc().initWithLength_(0) myDataObject.appendBytes_length_(fileType, len(fileType)) for myChunk in sys.stdin: myDataObject.appendBytes_length_(myChunk, len(myChunk)) pdfDoc = PDFDocument.alloc().initWithData_(myDataObject) encrypt(outFilename, pdfDoc) fileRef = open(outFilename, "w") fileRef.write(myDataObject.getBytes_length_(None, myDataObject.length())) fileRef.close # Fix file permissions of PDF for user fixPerms(outFilename) # Make sure everyone can read log. os.chmod(logFile, 0744)
def testFunctions(self): self.assertIsInstance(CGImageDestinationGetTypeID(), (int, long)) self.assertResultIsCFRetained(CGImageDestinationCopyTypeIdentifiers) v = CGImageDestinationCopyTypeIdentifiers() self.assertIsInstance(v, CFArrayRef) if v: self.assertIsInstance(v[0], unicode) data = NSMutableData.data() self.assertResultIsCFRetained(CGImageDestinationCreateWithData) dest = CGImageDestinationCreateWithData(data, v[0], 1, None) self.assertIsInstance(dest, CGImageDestinationRef) url = CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False) self.assertResultIsCFRetained(CGImageDestinationCreateWithURL) dest = CGImageDestinationCreateWithURL(url, "public.tiff", 2, None) self.assertIsInstance(dest, CGImageDestinationRef) CGImageDestinationSetProperties( dest, {b'key'.decode('latin1'): b'value'.decode('latin1')}) provider = CGDataProviderCreateWithCFData(buffer("1" * 4 * 100 * 80)) img = CGImageCreate(100, 80, 8, 32, 400, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast, provider, None, False, kCGRenderingIntentDefault) self.assertIsInstance(img, CGImageRef) CGImageDestinationAddImage(dest, img, None) image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif" if not os.path.exists(image_path): image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png" if not os.path.exists(image_path): image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff" url = CFURLCreateWithFileSystemPath(None, image_path, kCFURLPOSIXPathStyle, False) isrc = CGImageSourceCreateWithURL(url, None) CGImageDestinationAddImageFromSource(dest, isrc, 0, None) self.assertResultHasType(CGImageDestinationFinalize, objc._C_BOOL) v = CGImageDestinationFinalize(dest) self.assertIsInstance(v, bool) self.assertIs(v, True) dta = NSMutableData.alloc().init() cons = CGDataConsumerCreateWithCFData(dta) self.assertResultIsCFRetained(CGImageDestinationCreateWithDataConsumer) c = CGImageDestinationCreateWithDataConsumer(cons, 'public.tiff', 1, None) self.assertIsInstance(c, CGImageDestinationRef)
def testFunctions(self): self.assertIsInstance(CGImageDestinationGetTypeID(), (int, long)) self.assertResultIsCFRetained(CGImageDestinationCopyTypeIdentifiers) v = CGImageDestinationCopyTypeIdentifiers() self.assertIsInstance(v, CFArrayRef) if v: self.assertIsInstance(v[0], unicode) data = NSMutableData.data() self.assertResultIsCFRetained(CGImageDestinationCreateWithData) dest = CGImageDestinationCreateWithData(data, v[0], 1, None) self.assertIsInstance(dest, CGImageDestinationRef) url = CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False) self.assertResultIsCFRetained(CGImageDestinationCreateWithURL) dest = CGImageDestinationCreateWithURL(url, "public.tiff", 2, None) self.assertIsInstance(dest, CGImageDestinationRef) CGImageDestinationSetProperties(dest, {b'key'.decode('latin1'): b'value'.decode('latin1')}) provider = CGDataProviderCreateWithCFData(buffer("1" * 4 * 100 * 80)) img = CGImageCreate(100, 80, 8, 32, 400, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast, provider, None, False, kCGRenderingIntentDefault) self.assertIsInstance(img, CGImageRef) CGImageDestinationAddImage(dest, img, None) image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif" if not os.path.exists(image_path): image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png" if not os.path.exists(image_path): image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff" url = CFURLCreateWithFileSystemPath(None, image_path, kCFURLPOSIXPathStyle, False) isrc = CGImageSourceCreateWithURL(url, None) CGImageDestinationAddImageFromSource(dest, isrc, 0, None) self.assertResultHasType(CGImageDestinationFinalize, objc._C_BOOL) v = CGImageDestinationFinalize(dest) self.assertIsInstance(v, bool) self.assertIs(v, True) dta = NSMutableData.alloc().init() cons = CGDataConsumerCreateWithCFData(dta) self.assertResultIsCFRetained(CGImageDestinationCreateWithDataConsumer) c = CGImageDestinationCreateWithDataConsumer(cons, 'public.tiff', 1, None) self.assertIsInstance(c, CGImageDestinationRef)
def testFunctions(self): self.assertIsInstance(Quartz.CGImageDestinationGetTypeID(), int) self.assertResultIsCFRetained( Quartz.CGImageDestinationCopyTypeIdentifiers) v = Quartz.CGImageDestinationCopyTypeIdentifiers() self.assertIsInstance(v, Quartz.CFArrayRef) if v: self.assertIsInstance(v[0], str) data = NSMutableData.dataWithCapacity_(1024 * 1024 * 50) self.assertResultIsCFRetained(Quartz.CGImageDestinationCreateWithData) dest = Quartz.CGImageDestinationCreateWithData(data, v[0], 1, None) self.assertIsInstance(dest, Quartz.CGImageDestinationRef) url = Quartz.CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf", Quartz.kCFURLPOSIXPathStyle, False) self.assertResultIsCFRetained(Quartz.CGImageDestinationCreateWithURL) dest = Quartz.CGImageDestinationCreateWithURL(url, "public.tiff", 2, None) self.assertIsInstance(dest, Quartz.CGImageDestinationRef) Quartz.CGImageDestinationSetProperties(dest, {"key": "value"}) provider = Quartz.CGDataProviderCreateWithCFData( buffer("1" * 4 * 100 * 80)) img = Quartz.CGImageCreate( 100, 80, 8, 32, 400, Quartz.CGColorSpaceCreateDeviceRGB(), Quartz.kCGImageAlphaPremultipliedLast, provider, None, False, Quartz.kCGRenderingIntentDefault, ) self.assertIsInstance(img, Quartz.CGImageRef) Quartz.CGImageDestinationAddImage(dest, img, None) image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif" if not os.path.exists(image_path): image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png" if not os.path.exists(image_path): image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff" self.assertTrue(os.path.exists(image_path)) url = Quartz.CFURLCreateWithFileSystemPath(None, image_path, Quartz.kCFURLPOSIXPathStyle, False) isrc = Quartz.CGImageSourceCreateWithURL(url, None) Quartz.CGImageDestinationAddImageFromSource(dest, isrc, 0, None) self.assertResultHasType(Quartz.CGImageDestinationFinalize, objc._C_BOOL) v = Quartz.CGImageDestinationFinalize(dest) self.assertIsInstance(v, bool) self.assertIs(v, True) dta = NSMutableData.alloc().init() cons = Quartz.CGDataConsumerCreateWithCFData(dta) self.assertResultIsCFRetained( Quartz.CGImageDestinationCreateWithDataConsumer) c = Quartz.CGImageDestinationCreateWithDataConsumer( cons, "public.tiff", 1, None) self.assertIsInstance(c, Quartz.CGImageDestinationRef)