Example #1
0
File: gib.py Project: mctully/gib
def extract():
    if len(sys.argv)!=5:
        fatal('Wrong number of arguments for extract command')
    (backupname,snapshotname,destdir)=sys.argv[2:5]
    ref='refs/gib/%s/snapshots/%s'%(backupname,snapshotname)
    allRefs=getAllRefs()
    if ref in allRefs:
        tree=allRefs[ref]
        if os.path.exists(destdir):
            fatal("Destination %s' already exists - cannot extract!"%(destdir))
        clearIndex()
        git('read-tree',tree)
        if not destdir.endswith(os.sep):
            destdir+=os.sep
        if not os.path.isdir(destdir):
            os.makedirs(destdir)
        git('--work-tree=%s'%destdir,'checkout-index','-a')
        # get rid of the .gibkeep files that were only added to track empty dirs
        for file in str(git('ls-files','--cached')).splitlines():
            if file.endswith('.gibkeep'):
                pbs.rm(os.path.join(destdir,file))
        clearIndex()
        print "Extracted backup of '%s' snapshot '%s' to '%s'"%(backupname,snapshotname,destdir)
    else:
        fatal('Snapshot %s for backup %s does not exist\nTested %s'%(snapshotname,backupname,ref))
Example #2
0
def extract():
    if len(sys.argv) != 5:
        fatal('Wrong number of arguments for extract command')
    (backupname, snapshotname, destdir) = sys.argv[2:5]
    ref = 'refs/gib/%s/snapshots/%s' % (backupname, snapshotname)
    allRefs = getAllRefs()
    if ref in allRefs:
        tree = allRefs[ref]
        if os.path.exists(destdir):
            fatal("Destination %s' already exists - cannot extract!" %
                  (destdir))
        clearIndex()
        git('read-tree', tree)
        if not destdir.endswith(os.sep):
            destdir += os.sep
        if not os.path.isdir(destdir):
            os.makedirs(destdir)
        git('--work-tree=%s' % destdir, 'checkout-index', '-a')
        # get rid of the .gibkeep files that were only added to track empty dirs
        for file in str(git('ls-files', '--cached')).splitlines():
            if file.endswith('.gibkeep'):
                pbs.rm(os.path.join(destdir, file))
        clearIndex()
        print "Extracted backup of '%s' snapshot '%s' to '%s'" % (
            backupname, snapshotname, destdir)
    else:
        fatal('Snapshot %s for backup %s does not exist\nTested %s' %
              (snapshotname, backupname, ref))
Example #3
0
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)
Example #4
0
  def exe(self):
    filepath = self.motes_path + self.filename

    if path.isfile(filepath):
      delete_msg = 'Are you sure you want to delete the mote named `' + PathCleaner(self.filename).short() + '`?'
      delete_file = yes_no(delete_msg)
    
      if delete_file:
        pbs.rm(filepath)
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  
Example #6
0
def command_solr_slave(args):
    if args.config:
        checkout_dir = os.path.join(DIMHOLT_OPT, "solr_slave")
        if os.path.isdir(checkout_dir):
            pbs.rm("-rf", checkout_dir)
        pbs.git('clone', CODE_SOLR_URL, checkout_dir)