... | ... |
@@ -1951,9 +1951,12 @@ def cmd_setpolicy(args): |
1951 | 1951 |
s3 = S3(cfg) |
1952 | 1952 |
uri = S3Uri(args[1]) |
1953 | 1953 |
policy_file = args[0] |
1954 |
- policy = open(deunicodise(policy_file), 'r').read() |
|
1955 | 1954 |
|
1956 |
- if cfg.dry_run: return EX_OK |
|
1955 |
+ with open(deunicodise(policy_file), 'r') as fp: |
|
1956 |
+ policy = fp.read() |
|
1957 |
+ |
|
1958 |
+ if cfg.dry_run: |
|
1959 |
+ return EX_OK |
|
1957 | 1960 |
|
1958 | 1961 |
response = s3.set_policy(uri, policy) |
1959 | 1962 |
|
... | ... |
@@ -1981,9 +1984,12 @@ def cmd_setcors(args): |
1981 | 1981 |
s3 = S3(cfg) |
1982 | 1982 |
uri = S3Uri(args[1]) |
1983 | 1983 |
cors_file = args[0] |
1984 |
- cors = open(deunicodise(cors_file), 'r').read() |
|
1985 | 1984 |
|
1986 |
- if cfg.dry_run: return EX_OK |
|
1985 |
+ with open(deunicodise(cors_file), 'r') as fp: |
|
1986 |
+ cors = fp.read() |
|
1987 |
+ |
|
1988 |
+ if cfg.dry_run: |
|
1989 |
+ return EX_OK |
|
1987 | 1990 |
|
1988 | 1991 |
response = s3.set_cors(uri, cors) |
1989 | 1992 |
|
... | ... |
@@ -2026,9 +2032,12 @@ def cmd_setlifecycle(args): |
2026 | 2026 |
s3 = S3(cfg) |
2027 | 2027 |
uri = S3Uri(args[1]) |
2028 | 2028 |
lifecycle_policy_file = args[0] |
2029 |
- lifecycle_policy = open(deunicodise(lifecycle_policy_file), 'r').read() |
|
2030 | 2029 |
|
2031 |
- if cfg.dry_run: return EX_OK |
|
2030 |
+ with open(deunicodise(lifecycle_policy_file), 'r') as fp: |
|
2031 |
+ lifecycle_policy = fp.read() |
|
2032 |
+ |
|
2033 |
+ if cfg.dry_run: |
|
2034 |
+ return EX_OK |
|
2032 | 2035 |
|
2033 | 2036 |
response = s3.set_lifecycle_policy(uri, lifecycle_policy) |
2034 | 2037 |
|
... | ... |
@@ -2437,16 +2446,16 @@ def run_configure(config_file, args): |
2437 | 2437 |
|
2438 | 2438 |
def process_patterns_from_file(fname, patterns_list): |
2439 | 2439 |
try: |
2440 |
- fn = open(deunicodise(fname), "rt") |
|
2440 |
+ with open(deunicodise(fname), "rt") as fn: |
|
2441 |
+ for pattern in fn: |
|
2442 |
+ pattern = unicodise(pattern).strip() |
|
2443 |
+ if re.match("^#", pattern) or re.match("^\s*$", pattern): |
|
2444 |
+ continue |
|
2445 |
+ debug(u"%s: adding rule: %s" % (fname, pattern)) |
|
2446 |
+ patterns_list.append(pattern) |
|
2441 | 2447 |
except IOError as e: |
2442 | 2448 |
error(e) |
2443 | 2449 |
sys.exit(EX_IOERR) |
2444 |
- for pattern in fn: |
|
2445 |
- pattern = unicodise(pattern).strip() |
|
2446 |
- if re.match("^#", pattern) or re.match("^\s*$", pattern): |
|
2447 |
- continue |
|
2448 |
- debug(u"%s: adding rule: %s" % (fname, pattern)) |
|
2449 |
- patterns_list.append(pattern) |
|
2450 | 2450 |
|
2451 | 2451 |
return patterns_list |
2452 | 2452 |
|