From 8956796e7f462a49f499eac52fab901cdb59abdb Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 12 May 2012 14:12:03 +0200 Subject: [PATCH] Be explicit about complete-ability --- codegen/GenerateCode.py | 7 ---- .../description.000.human_readable.json | 28 ++++++++++++++ .../description.001.normalized.json | 37 +++++++++++++++++++ .../JsonDescriptionOfGithubApiV3/normalize.py | 4 +- src/github/GitTreeElement.py | 22 ----------- 5 files changed, 68 insertions(+), 30 deletions(-) diff --git a/codegen/GenerateCode.py b/codegen/GenerateCode.py index 6bfe424f..d10d7d4b 100644 --- a/codegen/GenerateCode.py +++ b/codegen/GenerateCode.py @@ -24,13 +24,6 @@ for class_ in description[ "classes" ]: dependencies.add( thing[ "type" ][ "name" ] ) class_[ "dependencies" ] = list( dependencies ) -for class_ in description[ "classes" ]: - isCompletable = False - for attribute in class_[ "attributes" ]: - if attribute[ "name" ] == "url": - isCompletable = True - class_[ "isCompletable" ] = isCompletable - githubObjectTemplate = django.template.loader.get_template( "GithubObject.py" ) for class_ in description[ "classes" ]: with open( os.path.join( os.path.dirname( __file__ ), "..", "src", "github", class_[ "name" ] + ".py" ), "w" ) as f: diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index 5525208f..543eef8e 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -13,6 +13,7 @@ }, { "name": "AuthenticatedUser", + "isCompletable": true, "url": [ { "type": "constant", "value": "https://api.github.com/user" } ], @@ -245,6 +246,7 @@ }, { "name": "Authorization", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "scopes", "type": "@todo" }, @@ -306,6 +308,7 @@ }, { "name": "Commit", + "isCompletable": true, "attributes": [ { "name": "files", "type": "list:CommitFile" }, { "name": "parents", "type": "list:Commit" }, @@ -338,6 +341,7 @@ }, { "name": "CommitComment", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "body", "type": "@todo" } @@ -362,6 +366,7 @@ }, { "name": "Download", + "isCompletable": true, "delete": true, "attributes": [ { "name": "accesskeyid", "type": "@todo" }, @@ -390,6 +395,7 @@ }, { "name": "Event", + "isCompletable": true, "attributes": [ { "name": "commit_id", "type": "@todo" }, { "name": "created_at", "type": "@todo" }, @@ -409,6 +415,7 @@ }, { "name": "Gist", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "description", "type": "string" }, @@ -509,6 +516,7 @@ }, { "name": "GistComment", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "body", "type": "@todo" } @@ -528,6 +536,7 @@ }, { "name": "GitBlob", + "isCompletable": true, "attributes": [ { "name": "content", "type": "string" }, { "name": "encoding", "type": "string" }, @@ -540,6 +549,7 @@ }, { "name": "GitCommit", + "isCompletable": true, "attributes": [ { "name": "author", "type": "GitAuthor" }, { "name": "committer", "type": "GitAuthor" }, @@ -554,6 +564,7 @@ }, { "name": "GitObject", + "isCompletable": true, "attributes": [ { "name": "sha", "type": "string" }, { "name": "type", "type": "string" }, @@ -564,6 +575,7 @@ }, { "name": "GitRef", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "sha", "type": "@todo" } @@ -583,6 +595,7 @@ }, { "name": "GitTag", + "isCompletable": true, "attributes": [ { "name": "message", "type": "string" }, { "name": "object", "type": "GitObject" }, @@ -609,6 +622,7 @@ }, { "name": "GitTree", + "isCompletable": true, "attributes": [ { "name": "sha", "type": "string" }, { "name": "tree", "type": "list:GitTreeElement" }, @@ -629,6 +643,7 @@ }, { "name": "Hook", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "name", "type": "@todo" }, @@ -673,6 +688,7 @@ }, { "name": "Issue", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "title", "type": "@todo" }, @@ -737,6 +753,7 @@ }, { "name": "IssueComment", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "body", "type": "@todo" } @@ -756,6 +773,7 @@ }, { "name": "IssueEvent", + "isCompletable": true, "attributes": [ { "name": "commit_id", "type": "@todo" }, { "name": "created_at", "type": "@todo" }, @@ -770,6 +788,7 @@ }, { "name": "Label", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "name", "type": "@todo" }, @@ -787,6 +806,7 @@ }, { "name": "Milestone", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "title", "type": "@todo" } @@ -821,6 +841,7 @@ }, { "name": "NamedUser", + "isCompletable": true, "attributes": [ { "name": "avatar_url", "type": "@todo" }, { "name": "bio", "type": "@todo" }, @@ -957,6 +978,7 @@ }, { "name": "Organization", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "billing_email", "type": "@todo" }, @@ -1093,6 +1115,7 @@ }, { "name": "PullRequest", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "title", "type": "@todo" }, @@ -1185,6 +1208,7 @@ }, { "name": "PullRequestComment", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "body", "type": "@todo" } @@ -1235,6 +1259,7 @@ }, { "name": "Repository", + "isCompletable": true, "identity": [ { "type": "attribute", "value": [ "owner", "login" ] }, { "type": "constant", "value": "/" }, @@ -1668,6 +1693,7 @@ }, { "name": "RepositoryKey", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "title", "type": "@todo" }, @@ -1697,6 +1723,7 @@ }, { "name": "Team", + "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "name", "type": "@todo" } @@ -1737,6 +1764,7 @@ }, { "name": "UserKey", + "isCompletable": true, "edit": { "optionalParameters": [ { "name": "title", "type": "@todo" }, diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 93bf75f2..90ef3721 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -203,6 +203,7 @@ "name": "url" } ], + "isCompletable": true, "name": "AuthenticatedUser", "methods": [ { @@ -1577,6 +1578,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Authorization", "methods": [ { @@ -1694,6 +1696,7 @@ "name": "name" } ], + "isCompletable": false, "name": "Branch", "methods": [] }, @@ -1764,6 +1767,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Commit", "methods": [ { @@ -1964,6 +1968,7 @@ "name": "user" } ], + "isCompletable": true, "name": "CommitComment", "methods": [ { @@ -2105,6 +2110,7 @@ "name": "status" } ], + "isCompletable": false, "name": "CommitFile", "methods": [] }, @@ -2135,6 +2141,7 @@ "name": "total" } ], + "isCompletable": false, "name": "CommitStats", "methods": [] }, @@ -2301,6 +2308,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Download", "methods": [ { @@ -2430,6 +2438,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Event", "methods": [] }, @@ -2548,6 +2557,7 @@ "name": "user" } ], + "isCompletable": true, "name": "Gist", "methods": [ { @@ -2909,6 +2919,7 @@ "name": "user" } ], + "isCompletable": true, "name": "GistComment", "methods": [ { @@ -3002,6 +3013,7 @@ "name": "name" } ], + "isCompletable": false, "name": "GitAuthor", "methods": [] }, @@ -3048,6 +3060,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitBlob", "methods": [] }, @@ -3110,6 +3123,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitCommit", "methods": [] }, @@ -3140,6 +3154,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitObject", "methods": [] }, @@ -3170,6 +3185,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitRef", "methods": [ { @@ -3296,6 +3312,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitTag", "methods": [] }, @@ -3326,6 +3343,7 @@ "name": "url" } ], + "isCompletable": true, "name": "GitTree", "methods": [] }, @@ -3380,6 +3398,7 @@ "name": "url" } ], + "isCompletable": false, "name": "GitTreeElement", "methods": [] }, @@ -3458,6 +3477,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Hook", "methods": [ { @@ -3734,6 +3754,7 @@ "name": "user" } ], + "isCompletable": true, "name": "Issue", "methods": [ { @@ -4180,6 +4201,7 @@ "name": "user" } ], + "isCompletable": true, "name": "IssueComment", "methods": [ { @@ -4305,6 +4327,7 @@ "name": "url" } ], + "isCompletable": true, "name": "IssueEvent", "methods": [] }, @@ -4335,6 +4358,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Label", "methods": [ { @@ -4492,6 +4516,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Milestone", "methods": [ { @@ -4825,6 +4850,7 @@ "name": "url" } ], + "isCompletable": true, "name": "NamedUser", "identity": [ { @@ -5460,6 +5486,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Organization", "methods": [ { @@ -6267,6 +6294,7 @@ "name": "push" } ], + "isCompletable": false, "name": "Permissions", "methods": [] }, @@ -6305,6 +6333,7 @@ "name": "space" } ], + "isCompletable": false, "name": "Plan", "methods": [] }, @@ -6519,6 +6548,7 @@ "name": "user" } ], + "isCompletable": true, "name": "PullRequest", "methods": [ { @@ -6879,6 +6909,7 @@ "name": "user" } ], + "isCompletable": true, "name": "PullRequestComment", "methods": [ { @@ -7020,6 +7051,7 @@ "name": "status" } ], + "isCompletable": false, "name": "PullRequestFile", "methods": [] }, @@ -7266,6 +7298,7 @@ "name": "watchers" } ], + "isCompletable": true, "name": "Repository", "identity": [ { @@ -9833,6 +9866,7 @@ "name": "url" } ], + "isCompletable": true, "name": "RepositoryKey", "methods": [ { @@ -9942,6 +9976,7 @@ "name": "zipball_url" } ], + "isCompletable": false, "name": "Tag", "methods": [] }, @@ -9996,6 +10031,7 @@ "name": "url" } ], + "isCompletable": true, "name": "Team", "methods": [ { @@ -10480,6 +10516,7 @@ "name": "url" } ], + "isCompletable": true, "name": "UserKey", "methods": [ { diff --git a/codegen/JsonDescriptionOfGithubApiV3/normalize.py b/codegen/JsonDescriptionOfGithubApiV3/normalize.py index 7dcc8e81..6610e119 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/normalize.py +++ b/codegen/JsonDescriptionOfGithubApiV3/normalize.py @@ -248,7 +248,7 @@ class Collection: class Class: def __init__( self, desc ): - checkKeys( desc, [ "name", "attributes", "collections" ], [ "url", "identity", "edit", "delete", "additionalMethods" ] ) + checkKeys( desc, [ "name", "attributes", "collections" ], [ "isCompletable", "url", "identity", "edit", "delete", "additionalMethods" ] ) self.name = desc[ "name" ] self.attributes = sorted( @@ -258,6 +258,7 @@ class Class: ], key = lambda class_: class_.name ) + self.isCompletable = "isCompletable" in desc and desc[ "isCompletable" ] self.methods = [] if "identity" in desc: self.identity = desc[ "identity" ] @@ -301,6 +302,7 @@ class Class: "name": self.name, "attributes": self.attributes, "methods": self.methods, + "isCompletable": self.isCompletable, } if self.identity is not None: d[ "identity" ] = self.identity diff --git a/src/github/GitTreeElement.py b/src/github/GitTreeElement.py index cc4e647a..75b69339 100644 --- a/src/github/GitTreeElement.py +++ b/src/github/GitTreeElement.py @@ -14,37 +14,29 @@ class GitTreeElement( object ): self.__completed = False self.__initAttributes() self.__useAttributes( attributes ) - if not lazy: - self.__complete() @property def mode( self ): - self.__completeIfNeeded( self.__mode ) return self.__mode @property def path( self ): - self.__completeIfNeeded( self.__path ) return self.__path @property def sha( self ): - self.__completeIfNeeded( self.__sha ) return self.__sha @property def size( self ): - self.__completeIfNeeded( self.__size ) return self.__size @property def type( self ): - self.__completeIfNeeded( self.__type ) return self.__type @property def url( self ): - self.__completeIfNeeded( self.__url ) return self.__url def __initAttributes( self ): @@ -55,20 +47,6 @@ class GitTreeElement( object ): self.__type = None self.__url = None - def __completeIfNeeded( self, testedAttribute ): - if not self.__completed and testedAttribute is None: - self.__complete() - - def __complete( self ): - status, headers, data = self.__requester.request( - "GET", - self.__url, - None, - None - ) - self.__useAttributes( data ) - self.__completed = True - def __useAttributes( self, attributes ): # @todo Remove this debug weakness: we shall assume that github will add new attributes for attribute in attributes: