[137931] branches/gsoc15-portfile/github2port
chunyang at macports.org
chunyang at macports.org
Tue Jun 23 01:21:17 PDT 2015
Revision: 137931
https://trac.macports.org/changeset/137931
Author: chunyang at macports.org
Date: 2015-06-23 01:21:16 -0700 (Tue, 23 Jun 2015)
Log Message:
-----------
Use more procedures
Modified Paths:
--------------
branches/gsoc15-portfile/github2port/bitbucket2port
branches/gsoc15-portfile/github2port/github2port
Modified: branches/gsoc15-portfile/github2port/bitbucket2port
===================================================================
--- branches/gsoc15-portfile/github2port/bitbucket2port 2015-06-23 08:20:46 UTC (rev 137930)
+++ branches/gsoc15-portfile/github2port/bitbucket2port 2015-06-23 08:21:16 UTC (rev 137931)
@@ -44,9 +44,6 @@
set project [lindex $path 1]
set tarball [lindex $path end]
- set version "version"
- set tag_prefix ""
-
return [concat $author $project [parse_tarball_name $tarball]]
}
Modified: branches/gsoc15-portfile/github2port/github2port
===================================================================
--- branches/gsoc15-portfile/github2port/github2port 2015-06-23 08:20:46 UTC (rev 137930)
+++ branches/gsoc15-portfile/github2port/github2port 2015-06-23 08:21:16 UTC (rev 137931)
@@ -1,9 +1,11 @@
-#!/usr/bin/env tclsh
+#!/usr/bin/env port-tclsh
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
#
# Generate a github group template Portfile given tarball or project URL
#
+package require uri
+
proc usage {{channel stderr}} {
global argv0
puts $channel "Usage: $argv0 URL"
@@ -20,61 +22,46 @@
expr {$val ne "" ? $val : $def}
}
-if {$argc != 1} {
- usage
- exit 1
-}
+proc parse_tarball_name {v} {
+ set version ""
+ set tag_prefix ""
-set url [lindex $argv 0]
-
-set author author
-set project project
-set version 1.0
-set tag_prefix ""; # tag_prefix, usually is empty or "v"
-
-set tarball_from ""; # tarball type, including release and others
-
-# 2.0, v0.3.8, release-v1.5.8, v0.8.5.tar.gz => version and tag_prefix if has
-proc parse_fancy_version {v} {
- global version
- global tag_prefix
if {[regexp {[0-9]+([.-][0-9]+)+} $v version]} {
if {[string length $version] < [string length $v]} {
set tag_prefix [string range $v 0 [expr [string first $version $v] -1]]
}
}
+ return [list $version $tag_prefix]
}
-if {[string match */releases/download/* $url]} {
- set tarball_from releases
+proc parse_github_url {url} {
+ array set urlparts [uri::split $url]
- set tmp [split $url /]
- set author [lindex $tmp 3]
- set project [lindex $tmp 4]
- # 2.0, v0.3.0
- set github_version [lindex $tmp 7]
- parse_fancy_version $github_version
-} elseif {[string match */archive/* $url]} {
- set tarball_from ""
+ if {![string equal $urlparts(host) github.com]} {
+ return -code error \
+ "expected github url but got \"$url\""
+ }
- set tmp [split $url /]
- set author [lindex $tmp 3]
- set project [lindex $tmp 4]
- # v0.8.5.tar.gz
- set tarball [lindex $tmp 6]
- parse_fancy_version $tarball
-} elseif {[string match *github* $url]} {
- set tmp [split $url /]
- set author [lindex $tmp 3]
- set project [lindex $tmp 4]
-} else {
- usage
- exit 1
+ set path [split $urlparts(path) /]
+ set author [lindex $path 0]
+ set project [lindex $path 1]
+ set tarball [lindex $path end]
+
+ set tarball_from [expr {[string match */releases/download/* $url] ? "release" : ""}]
+
+ return [concat $author $project [parse_tarball_name $tarball] $tarball_from]
}
-set description replaceme
-set homepage ""
+proc request_github {author project} {
+ set json "/tmp/${author}-${project}.json"
+ set api "https://api.github.com/repos/${author}/${project}"
+ exec curl --silent --max-time 5 --output $json $api
+ set description [val_or_def [parse_json .description $json] $description]
+ set homepage [val_or_def [parse_json .description $json] $homepage]
+ return [list description homepage]
+}
+
proc parse_json {query json} {
set tmp [exec jq $query $json]
set tmp [string range $tmp 1 end-1]
@@ -86,18 +73,23 @@
}
}
-proc request_github {} {
- global author project
- global description homepage
+if {$argc != 1} {
+ usage
+ exit 1
+}
- set json "/tmp/${author}-${project}.json"
- set api "https://api.github.com/repos/${author}/${project}"
- exec curl --silent --max-time 5 --output $json $api
+set url [lindex $argv 0]
+set tmp [parse_github_url $url]
- set description [val_or_def [parse_json .description $json] $description]
- set homepage [val_or_def [parse_json .description $json] $homepage]
-}
+set author [val_or_def [lindex $tmp 0] "author"]
+set project [val_or_def [lindex $tmp 1] "project"]
+set version [val_or_def [lindex $tmp 2] "version"]
+set tag_prefix [val_or_def [lindex $tmp 3] "tag_prefix"]
+set tarball_from [val_or_def [lindex $tmp 4] ""]
+set description replaceme
+set homepage ""
+
# request_github
puts "# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4"
@@ -109,7 +101,6 @@
puts ""
puts "github.setup ${author} ${project} ${version} ${tag_prefix}"
-# TODO: 6. (optional) Query categories, license etc from other Package Manager
puts "categories replaceme"
puts "platforms darwin"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150623/7751ee14/attachment-0001.html>
More information about the macports-changes
mailing list