def post(self): find_key = db.Key.from_path('Spec', 1) key_batch = db.allocate_ids(find_key, 1) spec = Spec(id=key_batch[0]) new_id = spec.put().id() if self.request.body != '': self.put(new_id) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'id': new_id}))
def receiveInput(request): ConvForm = ConversionForm(request.REQUEST, request.FILES) if ConvForm.is_valid(): conv = Spec(upload=ConvForm.cleaned_data['upload'], url=ConvForm.cleaned_data['url'] ) conv.save(force_insert=True) # start the work in the background bg = DoWork(conv) bg.start() # give it a second, so we might skip the # waiting-page for quick transforms sleep(2) return HttpResponseRedirect(APPURL+'result/spec_%s.json'%(conv.pk)) else: return HttpResponseRedirect(APPURL)
def add_item(self, name, brand, category, product_code, **kwargs): item = Item(user=self.user) self.session.add(item) spec_names = { 'name': name, 'brand': brand, 'category': category, 'product_code': product_code } spec_names.update(kwargs) spec_names = dict((k.lower(), v) for k, v in spec_names.items()) specs = Spec.ensure(self.session, self.user, spec_names.keys()) for (name, value) in spec_names.items(): spec = select(specs, 'name', name) assert (spec is not None) item_spec = ItemSpec(item=item, spec=spec, value=value, user=self.user) self.session.add(item_spec) self.session.commit() return item
def delete(self, id=None): if id is None: self.response.set_status('404') return spec = Spec.get_by_id(int(id)) if spec: spec.key.delete() else: self.response.set_status('404')
def addSpec(): info = request.get_json() or {} entity = Spec(title=info["title"], category=info["category"], body=info["body"], picture=info["picture"]) db.session.add(entity) db.session.commit() return jsonify({"response": "ok"})
def get(self, id=None): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers.add_header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS') self.response.headers.add_header('Access-Control-Allow-Headers', 'X-Requested-With, content-type') if id: spec = Spec.get_by_id(int(id)) if spec: self.response.write(spec.json) else: self.response.set_status('404') else: group = self.request.get('group') sort_by = self.request.get('sortby') owner = self.request.get('owner') specs = Spec.get_infos( 1000, group, sort_by, owner ) # TODO: Increased output from 100 to 1000, must implement pagination eventually self.response.write(json.dumps(specs))
def edit_variant(self, variant1, **kwargs): variant_specs = variant1.variant_specs specs = Spec.ensure(self.session, self.user, kwargs.keys()) for (name, value) in kwargs.items(): variant_spec = select(variant_specs, lambda x: x.spec.name, name) spec = select(specs, 'name', name) if variant_spec is not None: if variant_spec.value == value: continue variant_spec.active = False variant_spec.expired_at = _get_datetime() new_variant_spec = VariantSpec(variant=variant1, spec=spec, value=value, user=self.user) self.session.add(new_variant_spec) self.session.commit()
def edit_item(self, item, **kwargs): item_specs = item.item_specs specs = Spec.ensure(self.session, self.user, kwargs.keys()) for (name, value) in kwargs.items(): item_spec = select(item_specs, lambda x: x.spec.name, name) spec = select(specs, 'name', name) if item_spec is not None: if item_spec.value == value: continue item_spec.active = False item_spec.expired_at = _get_datetime() item_spec = ItemSpec(item=item, spec=spec, value=value, user=self.user) self.session.add(item_spec) self.session.commit()
def put(self, id=None): if id is None: self.response.set_status('404') return spec = Spec.get_by_id(int(id)) if spec: # Spec Owner payload = json.loads(self.request.body) owner = payload['permissions']['owner'] # Current User user = users.get_current_user() if user and user.nickname() == owner: spec.load_json_with_id(self.request.body, id) spec.put() else: self.response.set_status('403') else: self.response.set_status('404')
def add_variant(self, item, cost_price, selling_price, quantity, **kwargs): variant = Variant(item=item, user=self.user) self.session.add(variant) spec_names = { 'cost_price': cost_price, 'selling_price': selling_price, 'quantity': quantity } spec_names.update(kwargs) specs = Spec.ensure(self.session, self.user, spec_names.keys()) for (name, value) in spec_names.items(): spec = select(specs, 'name', name) assert (spec is not None) variant_spec = VariantSpec(variant=variant, spec=spec, value=value, user=self.user) self.session.add(variant_spec) self.session.commit() return variant
print("Initializing Datastore") init() print("Basic Models" + "\r\n") print("Character Roles: ") for role in CharacterRole: print (role) print() print("Character Classes: ") for cclass in CharacterClass: print (cclass) print() spriest = Spec(character_class=CharacterClass.Priest, name="Shadow", role=CharacterRole.Caster) print("Created First Spec: ") print(str(spriest)) print() print("Initializing all specs ") models.seedSpecs() print("Specs seeded!") print() print("Dumping Specs: ") session = models.Session() for entry in session.query(Spec).all(): print(entry) print("All Specs dumped from DB!")
def add_spec(self, name): spec = Spec.Spec(name=name, user=self.user) self.session.add(spec) self.session.commit()
def main(): # this is a test version1 = SemanticVersion('1.0') version2 = SemanticVersion('5.3-alpha') version3 = SemanticVersion('5.3-alpha1') version4 = SemanticVersion('2.1.12') version5 = SemanticVersion('2.3.12-beta1021') version6 = SemanticVersion('4.4_build_4.4.000') version7 = SemanticVersion('11.6.5.1.1-20161213') version8 = SemanticVersion('3.0b1') version9 = SemanticVersion('2.0alpha1-20020829') version10 = SemanticVersion('0.94.5a-mapr') version11 = SemanticVersion('1.4.0rc3') version12 = SemanticVersion('1.2.rc1') print(f'{version1}: {version1.version}') print(f'{version2}: {version2.version}') print(f'{version3}: {version3.version}') print(f'{version4}: {version4.version}') print(f'{version5}: {version5.version}') print(f'{version6}: {version6.version}') print(f'{version7}: {version7.version}') print(f'{version8}: {version8.version}') print(f'{version9}: {version9.version}') print(f'{version10}: {version10.version}') print(f'{version11}: {version11.version}') print(f'{version12}: {version12.version}') # Begin tests print(" Begin Spec Tests ...") s = Spec('>=0.1.1') # At least 0.1.1 assert s.match(version2) == True s2 = Spec('>=2.1.1,<2.3.0') assert s2.match(version5) == False assert len(s2.specs) == 2 # Match all versions s3 = Spec('*') assert s3.match(version5) == True result = check_version_in_criteria([s, s2], version5) assert result == False # Tests for match_version_ranges assert match_version_ranges('1.3.3', ['<2.0.0,>1.0.0']) == True # True assert match_version_ranges('1.3.3', ['<2.0.0,>1.0.0'], ['>1.5.0']) == True # True assert match_version_ranges('1.3.3', ['<2.0.0,>1.0.0'], ['>1.3.0']) == False # False assert match_version_ranges('1.3.3b', ['>1.3.3']) == False # False assert match_version_ranges('1.3.3b', ['>1.3.3'], language='c') == True # True # Multiple version specs for the same major+minor versions assert match_version_ranges('1.0.1d', ['>=1.0.1a', '>=1.0.2,<1.0.2h'], language='c') == True # True assert match_version_ranges( '1.2.3', ['>=1.2.5,<1.2.8', '>=0.5.0']) == False # False # Uses exact match for non standard version spec # True, prints exception for invalid version string print("Test Exception") assert match_version_ranges('version_1_3_3', ['version_1_3_3', 'version_1_4_4']) == True # Fix unclean versions in db assert match_version_ranges('1.2####alpha', ['<1.3']) == True # True assert match_version_ranges('1', ['<1.3']) == True # True # Test error handling for unclean versions # Prints exception for invalid version string in range print("Test Exception") assert match_version_ranges('1.2', ['<1.3', '>4.2:alpha']) == True # True # Prints exception for invalid version number print("Test Exception") assert match_version_ranges('4.2:beta', ['<1.3', '>4.2-alpha']) == False # False # Version cleaning tests assert clean_ver('2_7') == '2.7.0' # True assert clean_ver('2.7Alpha1') == '2.7.0-alpha1' # True assert clean_ver('.7') == '0.7.0' # True # Match Version Ranges assert match_version_ranges("4.9.0", [">4.8.0"]) == True #True assert match_version_ranges("4.8.0", [">= 4.8.0"]) == True #True assert match_version_ranges("5.1.0", [">=4.8.0"]) == True #True assert match_version_ranges("4.7.0", ["<4.8.0"]) == True #True assert match_version_ranges("4.6.0", ["<=4.8.0"]) == True #True assert match_version_ranges("4.8.0", ["<=4.8.0"]) == True #True assert match_version_ranges("0.1.0", [">1.0.2 <=2.3.4"]) == False #False assert match_version_ranges("1.1.0", [">1.0.2 <=2.3.4"]) == True #True assert match_version_ranges("1.1.0", ["1.0.0 - 2.3.1"]) == True #True assert match_version_ranges("3.0.1", ["<1.0.0 || >=2.3.1"]) == True #True print( " Testing ranges with 'v' in first or second postion followed by version" ) assert match_version_ranges("4.0.0", ["~v4"]) == True #True assert match_version_ranges("3.0.0", ["^v4.0.0"]) == False #False assert match_version_ranges("0.0.2", ["^0.0.2"]) == True #True assert match_version_ranges("3.1.1", ["^3.1.1"]) == True # True assert match_version_ranges("1.0.2", ["~0.15.7"]) == False #False assert match_version_ranges("1.1.0", ["~1.0.0"]) == False # False print(" Testing range containing x with operator in front ") assert match_version_ranges("2.3.1", ["~2.3.x"]) == True # True assert match_version_ranges("2.4.0", ["~2.3.x"]) == False # False assert match_version_ranges("2.4.0", ["^2.3.x"]) == True #True assert match_version_ranges("3.0.0", ["^2.3.x"]) == False #False print(" Testing range containing only x with no operator in front ") assert match_version_ranges("1.1.1", ["1.1.x"]) == True #True assert match_version_ranges("1.2.1", ["1.x.x"]) == True # True assert match_version_ranges("1.2.1", ["1.x"]) == True # True assert match_version_ranges("2.2.1", ["1.x.x"]) == False # False assert match_version_ranges("2.2.1", ["1.x"]) == False # False print(" Testing range containing * with operator in front ") assert match_version_ranges("2.3.1", ["~2.3.*"]) == True #True assert match_version_ranges("2.4.0", ["~2.3.*"]) == False #False assert match_version_ranges("2.4.0", ["^2.3.*"]) == True #True assert match_version_ranges("3.0.0", ["^2.3.*"]) == False #False print(" Testing range containing only * with no operator in front ") assert match_version_ranges("1.1.1", ["1.1.*"]) == True #True assert match_version_ranges("1.2.1", ["1.*.*"]) == True # True assert match_version_ranges("1.2.1", ["1.*"]) == True # True assert match_version_ranges("2.2.1", ["1.*.*"]) == False # False assert match_version_ranges("2.2.1", ["1.*"]) == False # False print(" Testing range with no minor and patch ") assert match_version_ranges("1.2.0", ["1"]) == True # True assert match_version_ranges("1.2.1", ["^1"]) == True # True assert match_version_ranges("1.2.1", ["~1"]) == True # True assert match_version_ranges("2.0.0", ["^1"]) == False # False print(" Testing range containing all the versions ") assert match_version_ranges("4.6.0", ["*"]) == True #True assert match_version_ranges("5.6.0", [""]) == True #True assert match_version_ranges("5.6.0", ["^x"]) == True # True assert match_version_ranges("5.6.0", ["*.*.*"]) == True # True assert match_version_ranges("5.6.0", ["^*"]) == True # True assert match_version_ranges("1.2.0", ["x.x.x"]) == True # True assert match_version_ranges("1.2.0", ["x.*"]) == True # True assert match_version_ranges("1.2.0", ["x.x"]) == True # True assert match_version_ranges("1.2.0", ["^x.x.x"]) == True # True assert match_version_ranges("1.2.0", ["~*"]) == True # True assert match_version_ranges("1.2.0", ["*.*"]) == True # True print(" Testing range containing multiple || and , ") assert match_version_ranges( "1.8.0", [">=1.8.0,<2.0.0||>=2.1.0,<3.0.0"]) == True #True assert match_version_ranges( "3.1.0", [">=1.8.0,<2.0.0||>=2.1.0,<3.0.0"]) == False #False assert match_version_ranges( "2.2.0", [">=1.8.0,<2.0.0||>=2.1.0,<3.0.0"]) == True #True print( " Testing range containing multiple || and , with no patch version specified " ) assert match_version_ranges("1.2.0", [">=2.3 || >=1.2,<2"]) == True #True print(" Testing range containing && ") assert match_version_ranges("1.2.0", [">=0.7.25 && <4.0.0"]) == True # True assert match_version_ranges("4.2.0", [">=0.7.25 && <4.0.0"]) == False # False print( " Testing ranges containing - in between with operator in range parts " ) assert match_version_ranges("4.2.0", ["^3.0.0 - ^4.1.0"]) == True # True assert match_version_ranges("2.2.0", ["^3.0.0 - 4.1.0"]) == False # False assert match_version_ranges("3.2.0", ["3.0.0 - ^4.1.0"]) == True # True assert match_version_ranges("4.1.0", ["*4.1.0"]) == True # True assert match_version_ranges("4.2.0", ["*4.1.0"]) == False # False assert match_version_ranges("1.9.2", [">=1.9.1 - 1.9.7"]) == True # True print(" Testing ranges containing ~>= in front ") assert match_version_ranges("9.0.4", ["~>=9.0.3"]) == True # True assert match_version_ranges("9.1.2", ["~>=9.0.3"]) == False # False print(" Testing ranges containing ^= in front ") assert match_version_ranges("6.2.4", ["^=6.0.3"]) == True # True assert match_version_ranges("7.1.2", ["^=6.0.3"]) == False # False print(" Testing version cleaning ", clean_ver("1.4.0.SNAPSHOT")) assert clean_ver("1.4.0.SNAPSHOT") == "1.4.0-snapshot" assert clean_ver("1.4.0.RC") == "1.4.0-rc" assert clean_ver("1.4.0.RC1") == "1.4.0-rc1" assert clean_ver("1.4.0.RELEASE") == "1.4.0-release" assert clean_ver("1.0.0.cr") == "1.0.0-cr" assert clean_ver("1.0.0.b1", 'maven') == "1.0.0-b1" assert clean_ver("1.0.0.SEC", 'maven') == "1.0.0-sec" assert clean_ver("1.4.0.m1", 'maven') == "1.4.0-m1" print( " Testing range cleaning and matching version in range with official pre-released tags " ) assert clean_ranges(["^2.0.0-rc.17"]) == ['>=2.0.0-rc.17,<3.0.0'] assert clean_ranges(["~2.0.0-rc.17"]) == ['>=2.0.0-rc.17,<2.1.0'] assert match_version_ranges("3.0.0-rc.17", ["^2.0.0-rc.17"], language="npm") == False assert match_version_ranges("2.0.0-rc.17", ["^2.0.0-rc.17"], language="npm") == True assert match_version_ranges("2.0.0-alpha.17", ["^2.0.0-rc.17"], language="npm") == False assert match_version_ranges("2.0.0-rc.18", ["^2.0.0-rc.17"], language="npm") == True assert match_version_ranges("2.0.0-rc.16", ["^2.0.0-rc.17"], language="npm") == False assert match_version_ranges("2.0.0", ["^2.0.0-rc.17"], language="npm") == True assert match_version_ranges("3.0.0", ["^2.0.0-rc.17"], language="npm") == False print( " Testing range cleaning and matching version in range with non-official pre-released tags " ) assert clean_ranges(["^2.0.0-z.17"]) == ['>=2.0.0-z.17,<3.0.0'] assert clean_ranges(["~2.0.0-a.17"]) == ['>=2.0.0-a.17,<2.1.0'] assert match_version_ranges("3.0.0-z.17", ["^2.0.0-a.17"], language="npm") == False assert match_version_ranges("2.0.0-z.17", ["^2.0.0-a.17"], language="npm") == True assert match_version_ranges("2.0.0-m.17", ["^2.0.0-r.17"], language="npm") == False assert match_version_ranges( "2.0.0", ["^2.0.0-z.17"], language="npm") == True #Testing with released version assert match_version_ranges( "3.0.0", ["^2.0.0-z.17"], language="npm") == False #Testing with released version assert match_version_ranges("4.0.0", [">=2.0.0-z.17,<5.0.0"], language="npm") == True assert match_version_ranges("2.0.0-rc.17", ["^2.0.0-rc.17"], language="npm") == True assert match_version_ranges("2.1.0-rc.17", ["~2.0.0-rc.17"], language="npm") == False assert match_version_ranges("2.0.0-rc.17", ["~2.0.0-rc.17"], language="npm") == True assert match_version_ranges("2.0.0-rc.18", ["~2.0.0-rc.17"], language="npm") == True assert match_version_ranges("2.1.0-alpha", ["~2.0.0-rc.17"], language="npm") == False assert match_version_ranges('3.0.0-cee', ['^2.4.1'], language='npm') == False assert match_version_ranges('2.5.0-cee', ['~2.4.1'], language='npm') == False assert match_version_ranges('5.0.0-a', ['>=2.0.0 <5.0.0-rc'], language='npm') == True assert match_version_ranges('2.0.0-a', ['>=2.0.0 <5.0.0-rc'], language='npm') == False assert match_version_ranges('3.0.0-a', ['>=2.0.0 <5.0.0-rc'], language='npm') == False assert match_version_ranges('5.0.0-alpha.1', ['^4.14.1'], language='npm') == False print( " Testing comparison between prereleased versions and prereleased with released versions" ) assert compare("1.2.0-z", "1.2.0-s", language='npm') == True assert compare("1.2.0", "1.2.0-rc", language="npm") == True assert compare("1.2.0-rc", "1.2.0-alpha", language="npm") == True assert compare("1.2.0-rc.18", "1.2.0-rc.17", language="npm") == True assert compare("1.2.0-rc", "1.2.0-final", language="npm") == True print(" Testing comparison between released versions ") assert compare("2.2.0", "1.2.0", language='npm') == True assert compare("1.2.0.2", "1.2.0.1", language='npm') == True assert compare("1.2.0.2", "1.2.0.1", language='npm') == True print( " Testing sorting of versions(asc) having both prereleased and released versions " ) print(sort_versions_asc(["1.2.0-final", "1.2.0-rc"], language='npm')) print( sort_versions_asc( ["1.2.0-final.17", "1.2.0-final.16", "1.2.0-final.1"], language='npm')) print( sort_versions_asc([ "1.2.0", "1.2.0-rc", "2.0.0", "2.0.0-z", "2.0.0-f", "2.0.0-f.2", "2.0.0-f.1" ], language='npm')) print( sort_versions_asc(["1.2.0", "1.2.0.1", "2.0.0.1", "2.0.0", "3.0.0"], language="npm"))