Пример #1
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, "")

    info_hash = create_torrent(args.file,
                               "/opt/www/torrents/%s.torrent" % new.filename,
                               new.full_path)

    new.type = args.type
    new.info_hash = info_hash
    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)
Пример #2
0
 def test_modversion(self):
     ota = OTAPackage(MockZip())
     self.assertEqual(ota.modversion, "CyanogenMod-6.1.0-RC0-N1")
Пример #3
0
 def test_build_user(self):
     ota = OTAPackage(MockZip())
     self.assertEquals(ota.build_user, "username")
Пример #4
0
 def test_build_host(self):
     ota = OTAPackage(MockZip())
     self.assertEquals(ota.build_host, "localhost")
Пример #5
0
 def test_build_date(self):
     ota = OTAPackage(MockZip())
     self.assertEquals(ota.build_date, "Fri Oct  1 00:28:43 CDT 2010")
Пример #6
0
 def test_device(self):
     ota = OTAPackage(MockZip())
     self.assertEquals(ota.device, "passion")