[137089] branches/gsoc15-portfile
chunyang at macports.org
chunyang at macports.org
Thu Jun 4 07:57:45 PDT 2015
Revision: 137089
https://trac.macports.org/changeset/137089
Author: chunyang at macports.org
Date: 2015-06-04 07:57:45 -0700 (Thu, 04 Jun 2015)
Log Message:
-----------
port-create: Extract name and version from URL
Modified Paths:
--------------
branches/gsoc15-portfile/port-create.tcl
Added Paths:
-----------
branches/gsoc15-portfile/Makefile
branches/gsoc15-portfile/all.tcl
branches/gsoc15-portfile/port-create.test
Added: branches/gsoc15-portfile/Makefile
===================================================================
--- branches/gsoc15-portfile/Makefile (rev 0)
+++ branches/gsoc15-portfile/Makefile 2015-06-04 14:57:45 UTC (rev 137089)
@@ -0,0 +1,2 @@
+test: port-create.tcl all.tcl port-create.test
+ tclsh all.tcl
Added: branches/gsoc15-portfile/all.tcl
===================================================================
--- branches/gsoc15-portfile/all.tcl (rev 0)
+++ branches/gsoc15-portfile/all.tcl 2015-06-04 14:57:45 UTC (rev 137089)
@@ -0,0 +1,3 @@
+package require tcltest
+namespace import ::tcltest::*
+runAllTests
\ No newline at end of file
Property changes on: branches/gsoc15-portfile/all.tcl
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: branches/gsoc15-portfile/port-create.tcl
===================================================================
--- branches/gsoc15-portfile/port-create.tcl 2015-06-04 14:41:46 UTC (rev 137088)
+++ branches/gsoc15-portfile/port-create.tcl 2015-06-04 14:57:45 UTC (rev 137089)
@@ -8,8 +8,38 @@
# 2. Feed template
# 3. Print result
-set fp [open "Portfile.template" r]
-set template [read $fp]
-close $fp
+# Get tarball filename from tarball URL
+proc get_tarball_filename {url} {
+ set length [string length $url]
+ set last [string last "/" $url]
+ incr last; # Discard prefix "/"
+ return [string range $url $last $length]
+}
-puts $template
+# Get name from tarball filename
+proc get_name {tarball} {
+ set last_dash [string last "-" $tarball]
+ incr last_dash -1; # Discard suffix "-"
+ return [string range $tarball 0 $last_dash]
+}
+
+# Get version from tarball filename
+proc get_version {tarball} {
+ set rtv [regexp {(\d+\.)?(\d+\.)?(\*|\d+)} $tarball match]
+ if {$rtv == 1} {
+ return $match
+ } else {
+ return 0
+ }
+}
+
+proc read_template {file} {
+ set fp [open $file r]
+ set template [read $fp]
+ close $fp
+ return $template
+}
+
+proc feed_template {template metadata} {
+ return $template
+}
Added: branches/gsoc15-portfile/port-create.test
===================================================================
--- branches/gsoc15-portfile/port-create.test (rev 0)
+++ branches/gsoc15-portfile/port-create.test 2015-06-04 14:57:45 UTC (rev 137089)
@@ -0,0 +1,14 @@
+# -*- 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
+# port-create.test
+
+package require tcltest
+namespace import ::tcltest::*
+
+source port-create.tcl
+
+test get_simple_name_version {} -body {
+ set tarball [get_tarball_filename https://www.kernel.org/pub/software/scm/git/git-2.4.2.tar.gz]
+ list [get_name $tarball] [get_version $tarball]
+} -result [list git 2.4.2]
+
+cleanupTests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150604/9f514ae8/attachment.html>
More information about the macports-changes
mailing list