def insert_a_package(): p = Package() p.id = input('Package id / name: ').strip().lower() p.summary = input("Package summary: ").strip() p.author_name = input("Author: ").strip() p.license = input("License: ").strip() print("Release 1: ") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) r.size = int(input("Size in bytes: ")) p.releases.append(r) print("Release 2: ") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) r.size = int(input("Size in bytes: ")) p.releases.append(r) session = db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p = Package() p.id = input('Package id / name: ').strip().lower() p.summary = input('Package summary: ').strip() p.author_name = input('Author: ').strip() p.license = input('License: ').strip() print('Release 1:') r = Release() r.major_ver = int(input('Major Version: ')) r.minor_ver = int(input('Minor Version: ')) r.build_ver = int(input('Build Version: ')) r.size = int(input('Size in bytes: ')) p.releases.append(r) print('Release 2:') r = Release() r.major_ver = int(input('Major Version: ')) r.minor_ver = int(input('Minor Version: ')) r.build_ver = int(input('Build Version: ')) r.size = int(input('Size in bytes: ')) p.releases.append(r) session = db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p=Package() p.id=input("Package ID/Name:").strip().lower() p.summary=input("Summary: ").strip() p.license=input("Licence").strip() p.author_name=input("Author name").strip() print("Release 1") r=Release() r.major_ver=int(input("Major Version")) r.minor_ver=int(input("Minor Version")) r.build_ver=int(input("Build")) r.size=int(input("Size:")) p.releases.append(r) print("Release 2") r = Release() r.major_ver = int(input("Major Version")) r.minor_ver = int(input("Minor Version")) r.build_ver = int(input("Build")) r.size = int(input("Size:")) p.releases.append(r) session=db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p = Package() p.id = input("Package id / name: ").strip().lower() p.summary = input("Package summary: ").strip() p.author_name = input("Author: ").strip() p.license = input("License: ").strip() print("Release 1:") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) # this attaches the relationship with r to the Package p. sa will traverse this object and see this relationship # and know it must add r even if we don't explicitly do a session.add(r) here. Adding r here might be awkward since # we might have an auto generated p.primary_key, etc... p.releases.append(r) # if we want a second release object, we can do the same thing and again append to p.releases print("Release 2:") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) p.releases.append(r) session = db_session.create_session() # # Old way (before we had a db_session.create_session()). Old way also had no type hinting # # If you want to see what the session object can do, you can use type casting # import sqlalchemy.orm as orm # session: orm.Session = db_session.__factory() # # Now type session <dot> <tab> and everything is available! # Add the changes we want to commit to the db (don't need to add r's because of the relations we already appended) session.add(p) # Once we have changes to commit (all at once), do a commit session.commit()
def build_releases(package_id: str, releases: dict) -> List[Release]: db_releases = [] for k in releases.keys(): all_releases_for_version = releases.get(k) if not all_releases_for_version: continue v = all_releases_for_version[-1] r = Release() r.package_id = package_id r.major_ver, r.minor_ver, r.build_ver = make_version_num(k) r.created_date = parse(v.get('upload_time')) r.comment = v.get('comment_text') r.url = v.get('url') r.size = int(v.get('size', 0)) db_releases.append(r) return db_releases