def command_rabbitmq(args): if args.config: if not os.path.isdir(DIMHOLT_OPT): pbs.mkdir('-p', DIMHOLT_OPT) checkout_dir = os.path.join(DIMHOLT_OPT, "rabbitmq") if os.path.isdir(checkout_dir): pbs.rm("-rf", checkout_dir) pbs.git('clone', CODE_RABBITMQ_URL, checkout_dir)
def get_sharded_directory(base_dir, domain_name, create=True): hashed = hash_domain_thumb(domain_name) shard_dir = join(base_dir, hashed[0], hashed[0:2] , hashed[0:3]) if create: try: sh.mkdir("-p", shard_dir) except: pass return shard_dir
def create_motes_dir(self, path): try: pbs.mkdir(path) except pbs.ErrorReturnCode_1: CommandLogger('Motes directory already existed, no new directory is created.', True) self.set_path(path) except pbs.ErrorReturnCode_2: CommandError('Motes install directory could not be created. Permissions problem?').exe()
def capture(domain_name, screenshot_base, screenshot_timeout=15000, resize_widths=[], exact_sizes=[]): tmp_screenshot = utils.get_sharded_directory("/tmp/screenshot", domain_name) final_screenshot = utils.get_sharded_directory(screenshot_base, domain_name) try: pbs.mkdir("-p", tmp_screenshot) except: pass try: pbs.mkdir("-p", final_screenshot) except: pass hash_domain = utils.hash_domain_thumb(domain_name) try: name = "%s.png" % hash_domain original = join(tmp_screenshot, name) logging.info("taking full size screenshot to %s", original) os.environ["DISPLAY"] = ":1" # swapping this out to wrap the call to CutyCapt with a timeout so that we don't end up with hung procs #pbs.CutyCapt("--url=http://%s" % domain_name, "--out=%s" % original, "--max-wait=%s" % screenshot_timeout) pbs.timeout("45s", "CutyCapt", "--url=http://%s" % domain_name, "--out=%s" % original, "--max-wait=%s" % screenshot_timeout) logging.info("done taking full size screenshot to %s", original) for width in resize_widths: name = "%s-%d.png" % (hash_domain, width) resized = join(tmp_screenshot, name) logging.info("resizing to %d", width) pbs.convert(original, "-resize", "%d" % width, "-crop", "%dx%d+0+0" % (width, width * 3), "-quality", "75", resized) logging.info("done resizing to %d", width) for width, height in exact_sizes: name = "%s-%dx%d.png" % (hash_domain, width, height) resized = join(tmp_screenshot, name) logging.info("resizing to %dx%d", width, height) pbs.convert(original, "-resize", "%d" % width, "-extent", "%dx%d" % (width, height), "-quality", "75", resized) logging.info("done resizing to %dx%d", width, height) # prior to rsync'ing, remove the full size screenshot as we don't want to keep that pbs.rm(original, "-f") pbs.rsync("-a", tmp_screenshot + "/", final_screenshot + "/") return True except: logging.exception("error, but closing down screenshotter cleanly") return False finally: try: pbs.rm(tmp_screenshot, "-rf") except: pass