예제 #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
파일: addfile.py 프로젝트: shiznu/GetCM
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)
예제 #3
0
def process_file(args):
    init_database(create_engine(args.db_uri))
    session = DBSession()
    build_prop = os.path.dirname(args.file) + "/build.prop"
    build_prop_raw = open(build_prop).read()

    device_name = None
    for line in build_prop_raw.split("\n"):
        if line.startswith("ro.cm.device"):
            k, device_name = line.split("=")

    if device_name is None:
        device_name = "unknown"

    # Determine md5sum
    build_number = args.full_path.split("/")[1]
    zip_name = args.full_path.split("/")[-1]
    md5_url = "http://jenkins.cyanogenmod.com/job/android/%s/artifact/archive/%s.md5sum" % (build_number, zip_name)
    md5hash = urllib2.urlopen(md5_url).read().split(" ")[0]

    # Determine filesize
    file_url = "/job/android/%s/artifact/archive/%s" % (build_number, zip_name)
    conn = httplib.HTTPConnection("jenkins.cyanogenmod.com")
    conn.request("HEAD", file_url)
    res = conn.getresponse()
    file_size = res.getheader('content-length')

    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.info_hash = None
    new.size = file_size
    new.device = device_name
    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)
    logging.debug("Size = %s", new.size)

    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)
예제 #4
0
파일: addfile.py 프로젝트: ciwrl/GetCM
def process_file(args):
    init_database(create_engine(args.db_uri))
    session = DBSession()
    build_prop = os.path.dirname(args.file) + "/build.prop"
    build_prop_raw = open(build_prop).read()

    device_name = None
    build_date = None
    for line in build_prop_raw.split("\n"):
        if line.startswith("ro.cm.device"):
            k, device_name = line.split("=")
        if line.startswith("ro.build.date.utc"):
            k, build_date = line.split("=")

    if device_name is None:
        device_name = "unknown"

    # Determine md5sum
    build_number = args.full_path.split("/")[1]
    zip_name = args.full_path.split("/")[-1]
    md5_url = "http://jenkins.cyanogenmod.com/job/android/%s/artifact/archive/%s.md5sum" % (build_number, zip_name)
    md5hash = urllib2.urlopen(md5_url).read().split(" ")[0]

    # Determine filesize
    file_url = "/job/android/%s/artifact/archive/%s" % (build_number, zip_name)
    conn = httplib.HTTPConnection("jenkins.cyanogenmod.com")
    conn.request("HEAD", file_url)
    res = conn.getresponse()
    file_size = res.getheader('content-length')

    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.info_hash = None
    new.size = file_size
    new.device = device_name
    if args.timestamp is not None:
        new.date_created = datetime.fromtimestamp(args.timestamp)
    elif build_date is not None:
        new.date_created = datetime.fromtimestamp(int(build_date))
    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)
    logging.debug("Size = %s", new.size)

    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)