Пример #1
0
    def __init__(self):
        if len(sys.argv) == 2:
            self.configPath = sys.argv[1]
        else:
            self.configPath = "/etc/getcd.ini"

        config = ConfigParser()
        config.readfp(open(self.configPath, 'r'))
        init_database(create_engine(config.get('database', 'uri')))
Пример #2
0
    def __init__(self):
        if len(sys.argv) == 2:
            self.configPath = sys.argv[1]
        else:
            self.configPath = "/etc/getcd.ini"

        config = ConfigParser()
        config.readfp(open(self.configPath, 'r'))
        init_database(create_engine(config.get('database', 'uri')))
Пример #3
0
def process_file(args):
    init_database(create_engine(args.db_uri))
    session = DBSession()

    ota = OTAPackage(args.file)

    md5hash = md5sum(args.file)
    new = File.get_by_md5sum(md5hash)
    if new is None:
        new = File()
        new.md5sum = md5hash

    if args.url:
        new.filename = os.path.basename(args.url)
    else:
        new.filename = os.path.basename(args.file)

    if args.full_path:
        new.full_path = args.full_path
    else:
        new.full_path = args.file.replace(args.base_path, "")

    new.type = args.type
    new.size = os.path.getsize(args.file)
    new.device = ota.build_prop.get('ro.cm.device', 'unknown')
    if args.timestamp is not None:
        new.date_created = datetime.fromtimestamp(args.timestamp)
    else:
        new.date_created = datetime.fromtimestamp(os.path.getmtime(args.file))

    logging.debug("Filename = %s", new.filename)
    logging.debug("Type = %s", new.type)
    logging.debug("Device = %s", new.device)
    logging.debug("MD5 = %s", new.md5sum)

    try:
        session.add(new)
        session.commit()
        logging.info("File added successfully!")
    except IntegrityError:
        session.rollback()
        logging.error("File already exists: '%s'", new.filename)

    if args.url:
        logging.info("Removing temporary file '%s'", args.file)
        os.remove(args.file)