"Fossies" - the Fresh Open Source Software Archive

Member "Tardis-1.2.1/tools/fixSizes.py" (9 Jun 2021, 3462 Bytes) of package /linux/privat/Tardis-1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "fixSizes.py" see the Fossies "Dox" file reference documentation.

    1 #! /usr/bin/env python3
    2 # vim: set et sw=4 sts=4 fileencoding=utf-8:
    3 #
    4 # Tardis: A Backup System
    5 # Copyright 2013-2020, Eric Koldinger, All Rights Reserved.
    6 # kolding@washington.edu
    7 #
    8 # Redistribution and use in source and binary forms, with or without
    9 # modification, are permitted provided that the following conditions are met:
   10 #
   11 #     * Redistributions of source code must retain the above copyright
   12 #       notice, this list of conditions and the following disclaimer.
   13 #     * Redistributions in binary form must reproduce the above copyright
   14 #       notice, this list of conditions and the following disclaimer in the
   15 #       documentation and/or other materials provided with the distribution.
   16 #     * Neither the name of the copyright holder nor the
   17 #       names of its contributors may be used to endorse or promote products
   18 #       derived from this software without specific prior written permission.
   19 #
   20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   30 # POSSIBILITY OF SUCH DAMAGE.
   31 
   32 import time
   33 import sys
   34 import argparse
   35 import magic
   36 import os
   37 import io
   38 import json
   39 
   40 import Tardis
   41 from Tardis import Util
   42 from Tardis import TardisCrypto
   43 from Tardis import Config
   44 from Tardis import CacheDir
   45 from Tardis import CompressedBuffer
   46 
   47 args = None
   48 
   49 def processArgs():
   50     parser = argparse.ArgumentParser(description='Check contents of the DB against the file system', fromfile_prefix_chars='@', formatter_class=Util.HelpFormatter, add_help=False)
   51 
   52     (_, remaining) = Config.parseConfigOptions(parser)
   53 
   54     Config.addCommonOptions(parser)
   55     Config.addPasswordOptions(parser)
   56 
   57     parser.add_argument('--input', '-i', default=None, dest='input', required=True, type=argparse.FileType('r'), help='Input file')
   58 
   59     #parser.add_argument('--verbose', '-v',  action='count', default=0, dest='verbose',                  help='Increase the verbosity')
   60     parser.add_argument('--version',        action='version', version='%(prog)s ' + Tardis.__versionstring__,    help='Show the version')
   61     parser.add_argument('--help', '-h',     action='help')
   62 
   63     return parser.parse_args(remaining)
   64 
   65 def main():
   66     global args
   67     args = processArgs()
   68 
   69     password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
   70     (tardis, cache, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
   71 
   72     allData = json.load(args.input)
   73     sizes = allData['size']
   74     for i in sizes:
   75         checksum = i[0]
   76         actualSize = i[2]
   77         tardis.conn.execute("UPDATE Checksums SET DiskSize = :size WHERE Checksum = :cksum", {'size': actualSize, 'cksum': checksum })
   78 
   79     tardis.conn.commit()
   80 
   81     return 0
   82 
   83 if __name__ == "__main__":
   84     sys.exit(main())