Merge pull request #387 from TiberiumN/master

Removed deprecated warnings, also tiny refactoring
This commit is contained in:
Dominik Picheta 2017-08-10 20:43:31 +01:00 • committed by GitHub
commit 6b46dc1b31
4 changed files with 30 additions and 33 deletions

View file

@ -1089,7 +1089,7 @@ when isMainModule:
let currentExc = (ref NimbleError)(getCurrentException()) let currentExc = (ref NimbleError)(getCurrentException())
(error, hint) = getOutputInfo(currentExc) (error, hint) = getOutputInfo(currentExc)
except NimbleQuit: except NimbleQuit:
nil discard
finally: finally:
removeDir(getNimbleTempDir()) removeDir(getNimbleTempDir())

View file

@ -8,7 +8,7 @@ import
compiler/ast, compiler/modules, compiler/passes, compiler/passaux, compiler/ast, compiler/modules, compiler/passes, compiler/passaux,
compiler/condsyms, compiler/sem, compiler/semdata, compiler/condsyms, compiler/sem, compiler/semdata,
compiler/llstream, compiler/vm, compiler/vmdef, compiler/commands, compiler/llstream, compiler/vm, compiler/vmdef, compiler/commands,
compiler/msgs, compiler/magicsys, compiler/lists, compiler/idents, compiler/msgs, compiler/magicsys, compiler/idents,
compiler/nimconf compiler/nimconf
from compiler/scriptconfig import setupVM from compiler/scriptconfig import setupVM
@ -228,7 +228,7 @@ proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
let tmpNimscriptApiPath = getTempDir() / "nimblepkg" / "nimscriptapi.nim" let tmpNimscriptApiPath = getTempDir() / "nimblepkg" / "nimscriptapi.nim"
createDir(tmpNimscriptApiPath.splitFile.dir) createDir(tmpNimscriptApiPath.splitFile.dir)
writeFile(tmpNimscriptApiPath, nimscriptApi) writeFile(tmpNimscriptApiPath, nimscriptApi)
appendStr(searchPaths, getTempDir()) searchPaths.add(getTempDir())
initDefines() initDefines()
loadConfigs(DefaultConfig) loadConfigs(DefaultConfig)
@ -241,7 +241,7 @@ proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
registerPass(semPass) registerPass(semPass)
registerPass(evalPass) registerPass(evalPass)
appendStr(searchPaths, compiler_options.libpath) searchPaths.add(compiler_options.libpath)
when declared(resetAllModulesHard): when declared(resetAllModulesHard):
result = makeModule(scriptName) result = makeModule(scriptName)

View file

@ -186,7 +186,8 @@ proc fetchList*(list: PackageList, options: Options) =
priority = LowPriority) priority = LowPriority)
try: try:
downloadFile(url, tempPath, proxy = proxy) let client = newHttpClient(proxy = proxy)
client.downloadFile(url, tempPath)
except: except:
let message = "Could not download: " & getCurrentExceptionMsg() let message = "Could not download: " & getCurrentExceptionMsg()
display("Warning:", message, Warning) display("Warning:", message, Warning)

View file

@ -13,18 +13,22 @@ type
user: string user: string
pw: string pw: string
token: string ## base64 encoding of user:pw token: string ## base64 encoding of user:pw
http: HttpClient ## http client for doing API requests
const const
ApiKeyFile = "github_api_token" ApiKeyFile = "github_api_token"
ApiTokenEnvironmentVariable = "NIMBLE_GITHUB_API_TOKEN" ApiTokenEnvironmentVariable = "NIMBLE_GITHUB_API_TOKEN"
ReposUrl = "https://api.github.com/repos/"
proc userAborted() = proc userAborted() =
raise newException(NimbleError, "User aborted the process.") raise newException(NimbleError, "User aborted the process.")
proc createHeaders(a: Auth): string = proc createHeaders(a: Auth) =
(("Authorization: token $1\c\L" % a.token) & a.http.headers = newHttpHeaders({
"Content-Type: application/x-www-form-urlencoded\c\L" & "Authorization": "token $1" % a.token,
"Accept: */*\c\L") "Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*"
})
proc requestNewToken(cfg: Config): string = proc requestNewToken(cfg: Config): string =
display("Info:", "Please create a new personal access token on Github in" & display("Info:", "Please create a new personal access token on Github in" &
@ -47,7 +51,7 @@ proc requestNewToken(cfg: Config): string =
return token return token
proc getGithubAuth(cfg: Config): Auth = proc getGithubAuth(cfg: Config): Auth =
result.http = newHttpClient()
# always prefer the environment variable to asking for a new one # always prefer the environment variable to asking for a new one
if existsEnv(ApiTokenEnvironmentVariable): if existsEnv(ApiTokenEnvironmentVariable):
result.token = getEnv(ApiTokenEnvironmentVariable) result.token = getEnv(ApiTokenEnvironmentVariable)
@ -63,9 +67,8 @@ proc getGithubAuth(cfg: Config): Auth =
priority = HighPriority) priority = HighPriority)
except IOError: except IOError:
result.token = requestNewToken(cfg) result.token = requestNewToken(cfg)
createHeaders(result)
let resp = getContent("https://api.github.com/user", let resp = result.http.getContent("https://api.github.com/user").parseJson()
extraHeaders=createHeaders(result)).parseJson()
result.user = resp["login"].str result.user = resp["login"].str
display("Success:", "Verified as " & result.user, Success, HighPriority) display("Success:", "Verified as " & result.user, Success, HighPriority)
@ -78,8 +81,7 @@ proc isCorrectFork(j: JsonNode): bool =
proc forkExists(a: Auth): bool = proc forkExists(a: Auth): bool =
try: try:
let x = getContent("https://api.github.com/repos/" & a.user & "/packages", let x = a.http.getContent(ReposUrl & a.user & "/packages")
extraHeaders=createHeaders(a))
let j = parseJson(x) let j = parseJson(x)
result = isCorrectFork(j) result = isCorrectFork(j)
except JsonParsingError, IOError: except JsonParsingError, IOError:
@ -87,16 +89,14 @@ proc forkExists(a: Auth): bool =
proc createFork(a: Auth) = proc createFork(a: Auth) =
try: try:
discard postContent("https://api.github.com/repos/nim-lang/packages/forks", discard a.http.postContent(ReposUrl & "nim-lang/packages/forks")
extraHeaders=createHeaders(a))
except HttpRequestError: except HttpRequestError:
raise newException(NimbleError, "Unable to create fork. Access token" & raise newException(NimbleError, "Unable to create fork. Access token" &
" might not have enough permissions.") " might not have enough permissions.")
proc createPullRequest(a: Auth, packageName, branch: string) = proc createPullRequest(a: Auth, packageName, branch: string) =
display("Info", "Creating PR", priority = HighPriority) display("Info", "Creating PR", priority = HighPriority)
discard postContent("https://api.github.com/repos/nim-lang/packages/pulls", discard a.http.postContent(ReposUrl & "nim-lang/packages/pulls",
extraHeaders=createHeaders(a),
body="""{"title": "Add package $1", "head": "$2:$3", body="""{"title": "Add package $1", "head": "$2:$3",
"base": "master"}""" % [packageName, a.user, branch]) "base": "master"}""" % [packageName, a.user, branch])
@ -139,14 +139,15 @@ proc cleanupWhitespace(s: string): string =
proc editJson(p: PackageInfo; url, tags, downloadMethod: string) = proc editJson(p: PackageInfo; url, tags, downloadMethod: string) =
var contents = parseFile("packages.json") var contents = parseFile("packages.json")
doAssert contents.kind == JArray doAssert contents.kind == JArray
contents.add(%{ contents.add(%*{
"name": %p.name, "name": p.name,
"url": %url, "url": url,
"method": %downloadMethod, "method": downloadMethod,
"tags": %tags.split(), "tags": tags.split(),
"description": %p.description, "description": p.description,
"license": %p.license, "license": p.license,
"web": %url}) "web": url
})
writeFile("packages.json", contents.pretty.cleanupWhitespace) writeFile("packages.json", contents.pretty.cleanupWhitespace)
proc getPackageOriginUrl(a: Auth): string = proc getPackageOriginUrl(a: Auth): string =
@ -229,8 +230,3 @@ proc publish*(p: PackageInfo, o: Options) =
doCmd("git push " & getPackageOriginUrl(auth) & " " & branchName) doCmd("git push " & getPackageOriginUrl(auth) & " " & branchName)
createPullRequest(auth, p.name, branchName) createPullRequest(auth, p.name, branchName)
display("Success:", "Pull request successful.", Success, HighPriority) display("Success:", "Pull request successful.", Success, HighPriority)
when isMainModule:
import packageinfo
var p = getPkgInfo(getCurrentDir())
publish(p)