def test_expunge_cache_lock(self): def set_marker(d): time.sleep(0.5) target = os.path.join(d, "marker.%s." % os.getpid()) open(target, "w") from softwarecenter.expunge import ExpungeCache tmpdir = tempfile.mkdtemp() # create two ExpungeCache processes e1 = ExpungeCache([tmpdir], by_days=0, by_unsuccessful_http_states=True) e1._cleanup_dir = set_marker e2 = ExpungeCache([tmpdir], by_days=0, by_unsuccessful_http_states=True) e2._cleanup_dir = set_marker t1 = multiprocessing.Process(target=e1.clean) t1.start() t2 = multiprocessing.Process(target=e2.clean) t2.start() # wait for finish t1.join() t2.join() # ensure that the second one was not called self.assertEqual(len(glob.glob(os.path.join(tmpdir, "marker.*"))), 1)
metavar='directory', nargs='+', type=str, help='directories to be checked') parser.add_argument('--by-days', type=int, default=0, help='expire everything older than N days') parser.add_argument('--by-unsuccessful-http-states', action="store_true", help='expire any non 200 status responses') args = parser.parse_args() if args.debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) # sanity checking if args.by_days == 0 and not args.by_unsuccessful_http_states: print "Need either --by-days or --by-unsuccessful-http-states argument" sys.exit(1) # be nice os.nice(19) # do it cleaner = ExpungeCache(args.directories, args.by_days, args.by_unsuccessful_http_states, args.dry_run) cleaner.clean()
parser.add_argument( 'directories', metavar='directory', nargs='+', type=str, help='directories to be checked') parser.add_argument( '--by-days', type=int, default=0, help='expire everything older than N days') parser.add_argument( '--by-unsuccessful-http-states', action="store_true", help='expire any non 200 status responses') args = parser.parse_args() if args.debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) # sanity checking if args.by_days == 0 and not args.by_unsuccessful_http_states: print "Need either --by-days or --by-unsuccessful-http-states argument" sys.exit(1) # be nice os.nice(19) # do it cleaner = ExpungeCache(args.directories, args.by_days, args.by_unsuccessful_http_states, args.dry_run) cleaner.clean()