示例#1
0
文件: views.py 项目: vicever/OMS
def repo_version_add(request,
                     template_name='repository/repo_version_add.html'):
    form = VersionForm(request.POST or None)
    username = request.session['username']
    if form.is_valid():
        project_name = form.cleaned_data['repository'].repo_tag
        print project_name
        archive_path = os.path.join(form.cleaned_data['archive_path'],
                                    project_name)
        version = get_version(archive_path)
        if not version:
            return HttpResponse(
                "Your configuration specifies to merge with the ref 'master' from the remote, "
                "but no such ref was fetched.")
        if Version.objects.filter(version=version[0]):
            return HttpResponse("already exist.")
        else:
            version_object = Version(project=project_name,
                                     version=version[0],
                                     timestamp=version[1],
                                     author=version[2],
                                     content=version[3],
                                     vernier=u'0')
            version_object.save()

        return redirect('repo_version_list')

    return render(
        request, template_name, {
            'form': form,
            'var6': 'active',
            'username': username,
            'highlight2': 'active',
        })
示例#2
0
def new_version(travis_api_key, tag):
    """Allows Travis to mark a new version during build."""
    try:
        TravisKeys.get(travis_api_key)
    except TravisKeys.DoesNotExist:
        return "API key is invalid.", 403

    if tag.startswith("v"):
        tag = tag.lstrip("v")

    i = 0
    while True:
        try:
            Version.get(i)
            i += 1
        except Version.DoesNotExist:
            break

    r = requests.get(
        "https://api.github.com/repos/JakeMakesStuff/MagicCap/releases/tags/v{}"
        .format(tag))

    r.raise_for_status()
    j = r.json()

    Version(release_id=i, version=tag, changelogs=j['body'], beta="b"
            in tag).save()

    return "Release {} successfully saved to the database.".format(tag), 200
示例#3
0
 def post(self, script, version, user=None):
     if script.user.key() != user.key():
         return self.not_authorized()
     version = Version(script=script, body=self.request.get('script'))
     version.put()
     script.latest_version = version
     script.put()
     self.redirect('/%s' % script.id)
示例#4
0
 def post(self):
     user = users.get_current_user()
     body = self.request.get('script')
     if body:
         script = Script()
         script.put()
         version = Version(script=script, body=body)
         version.put()
         script.latest_version = version
         script.put()
         self.redirect('/%s' % script.id)
     else:
         self.redirect('/new')
	def __init__(self, data, uuid):
		print "Gamestart registered"
		version = data['version']
		new_version = Version.create_or_fetch(version)
		os_info = OSInfo.get_os_info(data['system'], data['release'])
		gamestart = GameStart(uuid, new_version, os_info)
		db.session.add(gamestart)
		db.session.commit()
def construct_version_msg():
    version = MY_VERSION
    services = 1024 + 8 + 4 + 2 + 1  # turn 'em all on
    timestamp = math.floor(datetime.datetime.utcnow().timestamp())
    addr_recv = Address(services=services, ip=0, port=0, time=None)
    addr_from = Address(services=services, ip=0, port=0, time=None)
    nonce = make_nonce(8)
    user_agent = USER_AGENT
    # FIXME
    start_height = 1
    relay = 1
    v = Version(version, services, timestamp, addr_recv, addr_from, nonce,
                user_agent, start_height, relay)

    command = encode_command(b'version')
    payload = v.serialize()
    msg = Message(command, payload)
    return msg
def latest_versions():
    """Gets information about the latest MagicCap releases."""
    latest_release = None
    latest_beta = None

    release_id = 0
    while True:
        try:
            v = Version.get(release_id)
            if v.beta:
                latest_beta = v
            else:
                latest_release = v
            release_id += 1
        except Version.DoesNotExist:
            break

    beta_json = None
    beta_newer = False
    if latest_beta:
        beta_json = {
            "mac":
            "https://s3.magiccap.me/upgrades/v{}/magiccap-mac.dmg".format(
                latest_beta.version),
            "linux":
            "https://s3.magiccap.me/upgrades/v{}/magiccap-linux.zip".format(
                latest_beta.version),
            "changelogs":
            latest_beta.changelogs,
            "version":
            latest_beta.version
        }
        beta_newer = latest_beta.release_id > latest_release.release_id

    return jsonify({
        "beta": beta_json,
        "release": {
            "mac":
            "https://s3.magiccap.me/upgrades/v{}/magiccap-mac.dmg".format(
                latest_release.version),
            "linux":
            "https://s3.magiccap.me/upgrades/v{}/magiccap-linux.zip".format(
                latest_release.version),
            "changelogs":
            latest_release.changelogs,
            "version":
            latest_release.version
        },
        "is_beta_newer_than_release": beta_newer
    })
示例#8
0
def scrap_version(all_versions, model_name):
    result_versions = []
    i = 1

    for version in all_versions:
        print(f"Version: {i}/{len(all_versions)}")
        i += 1
        spec_tables = []
        technical = []

        link = f"https://www.ultimatespecs.com/{version}"
        version_soup = get_body_content(link)

        # rendered_page = render_page(link)
        # version_soup = bs(rendered_page, "html.parser").body

        version = version_soup.find(class_="ficha_specs_main")
        version_name = version.find(class_="spec_title").find("span").text
        version_code = version_name.replace(model_name, "").strip()
        version_year = version_soup.find(class_="right_column").find("b").text
        version_year = get_year_period(version_year)
        specification_div = version.select(
            ".ficha_specs_left, .ficha_specs_right")

        # Getting spec sections
        for div in specification_div:
            tables = div.select("table")
            spec_tables += tables

        # Getting specifications from spec section
        for table in spec_tables:
            table_title_div = table.find(class_="spec_title")
            if table_title_div == None:
                continue

            table_title = clear_text(table_title_div.text).replace(
                f"{version_name} ", "")
            if table_title in titles_template.keys():
                table_title = titles_template[table_title]

            rows = table.select("tr")
            technical.append(scrap_specification(rows, table_title))

        version_object = Version(version_name, version_code, version_year,
                                 technical)
        result_versions.append(version_object)

    return result_versions
def get_updates(release_id, beta):
    """Gets all updates that is avaliable for the user."""
    updates = []
    current_id = release_id + 1
    while True:
        try:
            u = Version.get(current_id)

            if u.beta:
                if beta:
                    updates.append(u)
            else:
                updates.append(u)

            current_id += 1
        except Version.DoesNotExist:
            break

    return updates
示例#10
0
def init_db():

    brand = Brand(name='Ford', brand_id=1, country='US').save()
    Brand(name='Ford2', brand_id=2, country='US').save()
    brand.save()

    fiesta = Car(brand=brand, name='Fiesta', car_id=1)
    edge = Car(brand=brand, name='Edge', car_id=2)
    ecosport = Car(brand=brand, name='Ecosport', car_id=3)
    ka = Car(brand=brand, name='Ka', car_id=4)

    flex_counter = 0
    gas_counter = 0

    for car in [fiesta, edge, ecosport, ka]:

        flex_counter += 1
        gas_counter += 1

        car.save()

        flex_version = Version(price=random.randrange(0, 50000),
                               model=car,
                               name='{name} {fuel} - {year}'.format(
                                   name=car.name,
                                   fuel='Flex',
                                   year=2011,
                                   version_id=flex_counter))
        gasoline_version = Version(price=random.randrange(0, 50000),
                                   model=car,
                                   name='{name} {fuel} - {year}'.format(
                                       name=car.name,
                                       fuel='Gasolina',
                                       year=2011,
                                       version_id=gas_counter))

        flex_version.save()
        gasoline_version.save()
示例#11
0
def version(req, mode):
    """
    Gets or set the version for the current ``mode``

    :param req:
    :param mode: the mode
    :return: an object with current version (``currentVersion``)
    """
    v = Version.query(Version.type == mode).get()
    if req.method == 'GET':
        if not v:
            raise NotFoundException
        return dict(currentVersion=v.current)
    elif req.method == "PUT":
        if not v:
            v = Version()
            v.type = mode
        vset = str(json.loads(req.body)['currentVersion'])
        v.current = vset
        v.put()
        return 200, dict(currentVersion=v.current)
示例#12
0
# This code is a part of MagicCap which is a MPL-2.0 licensed project.
# Copyright (C) Jake Gealer <*****@*****.**> 2018-2019.

from models import Version, TravisKeys, IPHashTimestamps, UnvalidatedGlobalKeyRequests, GlobalKeys, OneTimeKeys, InstallID
# Imports go here.


if not Version.exists():
    Version.create_table()

if not TravisKeys.exists():
    TravisKeys.create_table()

if not IPHashTimestamps.exists():
    IPHashTimestamps.create_table()

if not UnvalidatedGlobalKeyRequests.exists():
    UnvalidatedGlobalKeyRequests.create_table()

if not GlobalKeys.exists():
    GlobalKeys.create_table()

if not OneTimeKeys.exists():
    OneTimeKeys.create_table()

if not InstallID.exists():
    InstallID.create_table()
# Creates the tables if they do not exist.
示例#13
0
def test_setup(**kwargs):
    from django.contrib.auth.models import User
    from random import choice
    from desktopsite.apps.snapboard import chomsky
    from desktopsite.apps.repository.categories import REPOSITORY_CATEGORIES
    from models import Package, Rating, Version
    import datetime
    if not settings.DEBUG:
        return 

    if Package.objects.all().count() > 0:
        # return, since there seem to already be threads in the database.
        return
    
    # ask for permission to create the test
    msg = """
    You've installed Repository with DEBUG=True, do you want to populate
    the board with random users/packages/ratings to test-drive the application?
    (yes/no):
    """
    populate = raw_input(msg).strip()
    while not (populate == "yes" or populate == "no"):
        populate = raw_input("\nPlease type 'yes' or 'no': ").strip()
    if populate == "no":
        return

    # create 10 random users

    users = ('john', 'sally', 'susan', 'amanda', 'bob', 'tully', 'fran'
             'rick', 'alice', 'mary', 'steve', 'chris', 'becca', 'rob'
             'peter', 'amy', 'bill', 'nick', 'dustin', 'alex', 'jesus')
    for u in users:
        user, created = User.objects.get_or_create(username=u)
        user.email = "%s@%s.com" % (u, u)
        user.set_password(u)
        user.save()
        # user.is_staff = True

    # create up to 30 posts
    tc = range(1, 20)
    words = chomsky.objects.split(' ')
    for i in range(0, 20):
        print 'package ', i, 'created'
        subj = words[i]+" "+words[i-4]+" "+words[i+2]+" "+words[i-3]
        package = Package(
                        name=subj,
                        sysname=subj.replace(" ", "_").replace(".", "").replace("(", "").replace(")", "").replace("\n", ""),
                        category=choice(REPOSITORY_CATEGORIES)[0],
                        description = '\n\n'.join([chomsky.chomsky() for x in range(0, choice(range(2, 5)))]),
                        maintainer=choice(User.objects.all()),
                        url="http://www.foo.com/",
                       )
        package.save()
        
        for j in range(0, choice(range(1, 10))):
            text = '\n\n'.join([chomsky.chomsky() for x in range(0, choice(range(2, 5)))])
            v=Version(
              name="%s.%s.%s" % (choice(range(1, 5)), choice(range(1, 50)), choice(range(1, 170))),
              package=package,
              changelog=text,
              #package_url="http://www.foo.com/bar.lucid.zip",
              checksum= "".join([choice("abcdef0123456789") for x in range(1, 50)]),
              verified_safe=choice((True, False)),
            )
            v.save()
            
            for adf in range(0, choice(tc)):
                rating = Rating(
                              user=User.objects.get(pk=adf+1),
                              version= v,
                              score=choice((1,2,3,4,5)),
                )
                rating.save()
示例#14
0
def handle_version(payload, sock):
    version_msg = Version.parse(payload)
    print(services_int_to_dict(version_msg.services))
    print(version_msg)