~ubuntu-branches/debian/jessie/mysql-utilities/jessie

« back to all changes in this revision

Viewing changes to mysql/utilities/command/diskusage.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-05-14 15:02:12 UTC
  • mfrom: (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130514150212-cfj83guqqo0kx7l0
Tags: 1.1.2-1
* Upload to unstable.
* "X-Python-Version: >= 2.7" to stop using deprecated python-2.6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
            if os.path.isfile(itemfolder):
138
138
                total_size += os.path.getsize(itemfolder)
139
139
            elif os.path.isdir(itemfolder):
140
 
                total_size += getfolderSize(itemfolder)
 
140
                total_size += _get_db_dir_size(itemfolder)
141
141
    return total_size
142
142
 
143
143
 
150
150
    """
151
151
    total = 0
152
152
    tablespaces = []
153
 
    for item in os.listdir(folder):
154
 
        itempath = os.path.join(folder, item)
155
 
        if os.path.isfile(itempath):
 
153
    # skip inaccessible files.
 
154
    try:
 
155
        for item in os.listdir(folder):
 
156
            itempath = os.path.join(folder, item)
156
157
            name, ext = os.path.splitext(item)
157
 
            if ext.upper() == "IBD":
158
 
                size = os.path.getsize(itempath)
159
 
                total += size
160
 
                if verbosity > 0:
161
 
                    row = (item, size,'file tablespace', '')
162
 
                else:
163
 
                    row = (item, size)
164
 
 
165
 
                tablespaces.append(row)
166
 
        else:
167
 
            subdir, tot = _find_tablespace_files(itempath, verbosity)
168
 
            total += tot
169
 
            tablespaces.extend(subdir)
 
158
            if os.path.isfile(itempath):
 
159
                name, ext = os.path.splitext(item)
 
160
                if ext.upper() == "IBD":
 
161
                    size = os.path.getsize(itempath)
 
162
                    total += size
 
163
                    if verbosity > 0:
 
164
                        row = (item, size,'file tablespace', '')
 
165
                    else:
 
166
                        row = (item, size)
 
167
    
 
168
                    tablespaces.append(row)
 
169
            else:
 
170
                subdir, tot = _find_tablespace_files(itempath, verbosity)
 
171
                if subdir is not None:
 
172
                    total += tot
 
173
                    tablespaces.extend(subdir)
 
174
    except:
 
175
        return (None, None)
170
176
 
171
177
    return tablespaces, total
172
178
 
427
433
            # Put in commas and justify strings
428
434
            for i in range(0,num_cols):
429
435
                fmt_data[i] = locale.format("%d", row[i+1], grouping=True)
430
 
                fmt_data[i] = "{0:>{1}}".format(dbdir_size, max_col[i])
431
 
                if num_cols == 4: # get all columns
432
 
                    fmt_rows.append((row[0], fmt_data[0], fmt_data[1],
433
 
                                     fmt_data[2], fmt_data[3]))
434
 
                elif num_cols == 3:
435
 
                    fmt_rows.append((row[0], fmt_data[0], fmt_data[1],
436
 
                                     fmt_data[2]))
437
 
                else:
438
 
                    fmt_rows.append((row[0], fmt_data[0]))
 
436
            if num_cols == 4: # get all columns
 
437
                fmt_rows.append((row[0], fmt_data[0], fmt_data[1],
 
438
                                 fmt_data[2], fmt_data[3]))
 
439
            elif num_cols == 3:
 
440
                fmt_rows.append((row[0], fmt_data[0], fmt_data[1],
 
441
                                 fmt_data[2]))
 
442
            else:
 
443
                fmt_rows.append((row[0], fmt_data[0]))
439
444
    else:
440
445
        fmt_rows = results
441
446
 
454
459
                    if format:
455
460
                        fmt_data = ['','','','','']
456
461
                        for i in range(0,num_cols):
457
 
                            fmt_data[i] = locale.format("%d",
458
 
                                                        row[i+1], grouping=True)
459
 
                            fmt_data[i] = "{0:>{1}}".format(dbdir_size,
460
 
                                                            max_col[i])
461
 
                            if num_cols == 4: # get all columns
462
 
                                fmt_rows.insert(0, (db[0], fmt_data[0],
463
 
                                                    fmt_data[1], fmt_data[2],
464
 
                                                    fmt_data[3]))
465
 
                            elif num_cols == 3:
466
 
                                fmt_rows.insert(0, (db[0], fmt_data[0],
467
 
                                                 fmt_data[1], fmt_data[2]))
 
462
                            if type(row[i+1]) == type(int):
 
463
                                fmt_data[i] = locale.format("%s",
 
464
                                                            int(row[i+1]),
 
465
                                                            grouping=True)
468
466
                            else:
469
 
                                fmt_rows.insert(0, (db[0], fmt_data[0]))
 
467
                                fmt_data[i] = locale.format("%s", row[i+1],
 
468
                                                            grouping=True)
 
469
                        if num_cols == 4: # get all columns
 
470
                            fmt_rows.insert(0, (db[0], fmt_data[0],
 
471
                                                fmt_data[1], fmt_data[2],
 
472
                                                fmt_data[3]))
 
473
                        elif num_cols == 3:
 
474
                            fmt_rows.insert(0, (db[0], fmt_data[0],
 
475
                                             fmt_data[1], fmt_data[2]))
 
476
                        else:
 
477
                            fmt_rows.insert(0, (db[0], fmt_data[0]))
470
478
                    else:
471
479
                        if num_cols == 4:
472
480
                            fmt_rows.insert(0, (db[0], 0, 0, 0, 0))
662
670
        if not quiet:
663
671
            print "Current %s file = %s" % (log_type, current_log)
664
672
 
665
 
        logs, total = _build_log_list(datadir,
666
 
                                      os.path.splitext(current_log)[0])
 
673
        # As of 5.6.2, users can specify location of binlog and relaylog.
 
674
        if server.check_version_compat(5, 6, 2):
 
675
            if log_type == 'binary log':
 
676
                res = server.show_server_variable("log_bin_basename")[0]
 
677
            else:
 
678
                res = server.show_server_variable("relay_log_basename")[0]
 
679
            parts = os.path.split(res[1])
 
680
            log_path = os.path.join(parts[:len(parts) - 1])[0]
 
681
            log_prefix = parts[len(parts) - 1]
 
682
        else:
 
683
            log_path = datadir
 
684
            log_prefix = os.path.splitext(current_log)[0]
 
685
        if log_path == '':
 
686
            log_path = datadir
 
687
            
 
688
        logs, total = _build_log_list(log_path, log_prefix)
667
689
        if logs == []:
668
690
            raise UtilError("The %s are missing." % log_type)
669
691