Am 8. März 2011 16:37 schrieb Iustin Pop <[email protected]>:
> On Tue, Mar 08, 2011 at 04:11:31PM +0100, Michael Hanselmann wrote:
>> --- a/tools/cfgupgrade
>> +++ b/tools/cfgupgrade
>> +  if not options.dry_run:
>> +    if (os.path.isfile(options.RAPI_USERS_FILE_PRE24) and
>> +        not os.path.islink(options.RAPI_USERS_FILE_PRE24)):
>> +      if os.path.exists(options.RAPI_USERS_FILE):
>> +        raise Error("Found pre-2.4 RAPI users file at %s, but another file"
>> +                    " already exists at %s" %
>> +                    (options.RAPI_USERS_FILE_PRE24, 
>> options.RAPI_USERS_FILE))
>> +      logging.info("Found pre-2.4 RAPI users file at %s, renaming to %s",
>> +                   options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
>> +      utils.RenameFile(options.RAPI_USERS_FILE_PRE24, 
>> options.RAPI_USERS_FILE,
>> +                       mkdir=True, mkdir_mode=0750)
>> +
>> +    # Create a symlink for RAPI users file
>> +    if (not (os.path.islink(options.RAPI_USERS_FILE_PRE24) or
>> +             os.path.isfile(options.RAPI_USERS_FILE_PRE24)) and
>> +        os.path.isfile(options.RAPI_USERS_FILE)):
>> +      logging.info("Creating symlink from %s to %s",
>> +                   options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
>> +      os.symlink(options.RAPI_USERS_FILE, options.RAPI_USERS_FILE_PRE24)
>
> Please move just the utils.RenameFile under if not options.dry_run; the
> rest (checks + messages) should still execute, even in the dry_run case.

Done, see interdiff below.

> I'm also thinking that utils.RenameFile should always be followed by
> os.symlink, but it's also good as it is.

If the code is not incorrect, that should be the case. There are just
some additional checks.

Michael

---
--- a/tools/cfgupgrade
+++ b/tools/cfgupgrade
@@ -185,24 +185,25 @@ def main():
     raise Error("Configuration version %d.%d.%d not supported by this tool" %
                 (config_major, config_minor, config_revision))

-  if not options.dry_run:
-    if (os.path.isfile(options.RAPI_USERS_FILE_PRE24) and
-        not os.path.islink(options.RAPI_USERS_FILE_PRE24)):
-      if os.path.exists(options.RAPI_USERS_FILE):
-        raise Error("Found pre-2.4 RAPI users file at %s, but another file"
-                    " already exists at %s" %
-                    (options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE))
-      logging.info("Found pre-2.4 RAPI users file at %s, renaming to %s",
-                   options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
+  if (os.path.isfile(options.RAPI_USERS_FILE_PRE24) and
+      not os.path.islink(options.RAPI_USERS_FILE_PRE24)):
+    if os.path.exists(options.RAPI_USERS_FILE):
+      raise Error("Found pre-2.4 RAPI users file at %s, but another file"
+                  " already exists at %s" %
+                  (options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE))
+    logging.info("Found pre-2.4 RAPI users file at %s, renaming to %s",
+                 options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
+    if not options.dry_run:
       utils.RenameFile(options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE,
                        mkdir=True, mkdir_mode=0750)

-    # Create a symlink for RAPI users file
-    if (not (os.path.islink(options.RAPI_USERS_FILE_PRE24) or
-             os.path.isfile(options.RAPI_USERS_FILE_PRE24)) and
-        os.path.isfile(options.RAPI_USERS_FILE)):
-      logging.info("Creating symlink from %s to %s",
-                   options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
+  # Create a symlink for RAPI users file
+  if (not (os.path.islink(options.RAPI_USERS_FILE_PRE24) or
+           os.path.isfile(options.RAPI_USERS_FILE_PRE24)) and
+      os.path.isfile(options.RAPI_USERS_FILE)):
+    logging.info("Creating symlink from %s to %s",
+                 options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
+    if not options.dry_run:
       os.symlink(options.RAPI_USERS_FILE, options.RAPI_USERS_FILE_PRE24)

   try:

Reply via email to