summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
author B. Watson2022-07-10 23:26:54 +0200
committer Willy Sudiarto Raharjo2022-07-17 01:40:06 +0200
commited102aeab8ac4e4e4d00aa4975dd873bbec407ad (patch)
tree15e9ca0653452a81bef38be03dc8794879c4bcfb /system
parentdd7cab606606997bbda5874465ff90a6351c7d61 (diff)
downloadslackbuilds-ed102aeab8ac4e4e4d00aa4975dd873bbec407ad.tar.gz
system/csv2sql: Added (create sqlite database from a CSV file)
Signed-off-by: Dave Woodfall <dave@slackbuilds.org> Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'system')
-rw-r--r--system/csv2sql/README6
-rw-r--r--system/csv2sql/csv2sql.1162
-rw-r--r--system/csv2sql/csv2sql.SlackBuild68
-rw-r--r--system/csv2sql/csv2sql.info10
-rw-r--r--system/csv2sql/csv2sql.rst109
-rw-r--r--system/csv2sql/slack-desc19
-rw-r--r--system/csv2sql/stdin.diff19
7 files changed, 393 insertions, 0 deletions
diff --git a/system/csv2sql/README b/system/csv2sql/README
new file mode 100644
index 0000000000..8de8ec9317
--- /dev/null
+++ b/system/csv2sql/README
@@ -0,0 +1,6 @@
+csv2sql (create sqlite database from a CSV file)
+
+csv2sql is a Ruby script for importing comma-separated-value files
+into SQLite. It can read from a file or from standard input, and can
+create a new database or insert new data into an existing one. It can
+handle various character encodings; the default is UTF-8.
diff --git a/system/csv2sql/csv2sql.1 b/system/csv2sql/csv2sql.1
new file mode 100644
index 0000000000..b45e065bc7
--- /dev/null
+++ b/system/csv2sql/csv2sql.1
@@ -0,0 +1,162 @@
+.\" Man page generated from reStructuredText.
+.
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.TH "CSV2SQL" 1 "2022-07-09" "0.1" "SlackBuilds.org"
+.SH NAME
+csv2sql \- import data from CSV files into an SQLite database
+.\" RST source for csv2sql(1) man page. Convert with:
+.
+.\" rst2man.py csv2sql.rst > csv2sql.1
+.
+.\" rst2man.py comes from the SBo development/docutils package.
+.
+.SH SYNOPSIS
+.sp
+csv2sql [\fB\-d\fP | \fB\-\-database\fP \fIdatabase\fP] [\fB\-e\fP | \fB\-\-encoding\fP \fIencoding\fP \fIINPUT\fP:\fIOUTPUT\fP] [\fB\-f\fP | \fB\-\-file\fP \fIfilename\fP] [\fB\-h\fP | \fB\-\-help\fP] [\fB\-t\fP | \fB\-table\fP \fItable\fP] [\fB\-v\fP | \fB\-\-verbose\fP] [\fB\-V\fP | \fB\-\-version\fP]
+.SH DESCRIPTION
+.sp
+\fBcsv2sql\fP is a Ruby script for importing comma\-separated value files
+into SQLite.
+.sp
+The destination table and database will automatically be created if
+they do not already exist.
+.sp
+If the destination table already exists, then \fBcsv2sql\fP assumes that
+it contains the same number of columns as the input data. The column
+names do not need to match.
+.SH OPTIONS
+.INDENT 0.0
+.TP
+.BI \-d\fP,\fB \-\-database \ DATABASE
+Database to import into. Default is \fIcsv2sql.db\fP\&.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-e, \-\-encoding INPUT:OUTPUT
+Input and output encodings. Default is \fIUTF\-8:UTF\-8\fP\&.
+.UNINDENT
+.INDENT 0.0
+.TP
+.BI \-f\fP,\fB \-\-file \ FILENAME
+CSV file to import. You can alternately read CSV data from standard input.
+.TP
+.B \-h\fP,\fB \-\-help
+Print built\-in help message and exit.
+.TP
+.BI \-t\fP,\fB \-\-table \ TABLE
+Table to import into. Default is the name of the file being imported from or \fIstdin\fP if CSV data is from standard input. Periods in the filename are replaced with underscores.
+.TP
+.B \-v\fP,\fB \-\-verbose
+Print verbose output.
+.TP
+.B \-V\fP,\fB \-\-version
+Print version number and exit.
+.UNINDENT
+.SH NOTE
+.sp
+\fBcsv2sql\fP assumes the first line of CSV data is a header giving the
+column names. If your CSV file doesn\(aqt have column names (if the first
+line is just CSV data), you\(aqll have to edit it and add the column
+names for \fBcsv2sql\fP to work correctly with it.
+.SH EXAMPLES
+.INDENT 0.0
+.IP 1. 3
+Import widgets.csv into the default table (widgets_csv) and database (csv2sql.db):
+.INDENT 3.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+csv2sql \-f widgets.csv
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.IP 2. 3
+Import standard input into the "foo" table within the "bar.db" database:
+.INDENT 3.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+cat widgets.csv | csv2sql \-t foo \-d bar.db
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.IP 3. 3
+Import products.csv and more\-products.csv into the "products" table within the default database (csv2sql.db):
+.INDENT 3.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+csv2sql \-f products.csv \-t products
+csv2sql \-f more\-products.csv \-t products
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.IP 4. 3
+Export data from SQLite sorted by the "ProductName" column to output.csv:
+.INDENT 3.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+sqlite3 \-header \-csv csv2sql.db "SELECT * FROM products ORDER BY ProductName" > output.csv
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.SH COPYRIGHT
+.sp
+\fBcsv2sql\fP is open source software released under the MIT License. See:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+http://www.opensource.org/licenses/MIT
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.SH AUTHORS
+.sp
+\fBcsv2sql\fP was written by Matt Rideout.
+.sp
+This man page written for the SlackBuilds.org project
+by B. Watson, and is licensed under the WTFPL.
+.SH SEE ALSO
+.sp
+The csv2sql homepage: \fI\%http://csv2sql.org/\fP
+.\" Generated by docutils manpage writer.
+.
diff --git a/system/csv2sql/csv2sql.SlackBuild b/system/csv2sql/csv2sql.SlackBuild
new file mode 100644
index 0000000000..3fd9a532e0
--- /dev/null
+++ b/system/csv2sql/csv2sql.SlackBuild
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+# Slackware build script for csv2sql
+
+# Written by B. Watson (urchlay@slackware.uk)
+
+# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
+
+cd $(dirname $0) ; CWD=$(pwd)
+
+PRGNAM=csv2sql
+VERSION=${VERSION:-0.1}
+BUILD=${BUILD:-1}
+TAG=${TAG:-_SBo}
+PKGTYPE=${PKGTYPE:-tgz}
+ARCH=noarch
+
+if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
+ echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
+ exit 0
+fi
+
+TMP=${TMP:-/tmp/SBo}
+PKG=$TMP/package-$PRGNAM
+OUTPUT=${OUTPUT:-/tmp}
+
+set -e
+
+rm -rf $PKG
+mkdir -p $TMP $PKG $OUTPUT
+cd $TMP
+rm -rf $PRGNAM-$VERSION
+tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
+cd $PRGNAM-$VERSION
+chown -R root:root .
+chmod 644 *
+
+# As shipped, csv2sql refuses to read stdin if it's a redirect from a file.
+# This works:
+# cat file.csv | csv2sql
+# This doesn't work:
+# csv2sql < file.csv
+# ...which violates the principle of least surprise. The patch makes
+# it read from stdin unconditionally, if no filename given (so the 2nd
+# example will work). This is how standard UNIX utilities like cat,
+# grep, sed have worked for decades.
+# For those of you who don't like me patching the code, don't bother
+# complaining via email/etc. I consider this a bugfix that enhances
+# usability. Feel free to comment out the next line, if it bothers you:
+patch -p1 < $CWD/stdin.diff
+
+mkdir -p $PKG/usr/bin
+install -oroot -groot -m0755 $PRGNAM $PKG/usr/bin/$PRGNAM
+
+# man page by SlackBuild author.
+mkdir -p $PKG/usr/man/man1
+gzip -9c < $CWD/$PRGNAM.1 > $PKG/usr/man/man1/$PRGNAM.1.gz
+
+PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
+mkdir -p $PKGDOC
+cp -a README* $PKGDOC
+cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild
+
+mkdir -p $PKG/install
+cat $CWD/slack-desc > $PKG/install/slack-desc
+
+cd $PKG
+/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
diff --git a/system/csv2sql/csv2sql.info b/system/csv2sql/csv2sql.info
new file mode 100644
index 0000000000..230f488ad8
--- /dev/null
+++ b/system/csv2sql/csv2sql.info
@@ -0,0 +1,10 @@
+PRGNAM="csv2sql"
+VERSION="0.1"
+HOMEPAGE="http://csv2sql.org/"
+DOWNLOAD="https://github.com/mrideout/csv2sql/archive/v0.1/csv2sql-0.1.tar.gz"
+MD5SUM="8efce15a7114dd9d1ed3c5b2023f32fa"
+DOWNLOAD_x86_64=""
+MD5SUM_x86_64=""
+REQUIRES="sqlite3"
+MAINTAINER="B. Watson"
+EMAIL="urchlay@slackware.uk"
diff --git a/system/csv2sql/csv2sql.rst b/system/csv2sql/csv2sql.rst
new file mode 100644
index 0000000000..586fc13404
--- /dev/null
+++ b/system/csv2sql/csv2sql.rst
@@ -0,0 +1,109 @@
+.. RST source for csv2sql(1) man page. Convert with:
+.. rst2man.py csv2sql.rst > csv2sql.1
+.. rst2man.py comes from the SBo development/docutils package.
+
+.. |version| replace:: 0.1
+.. |date| date::
+
+=======
+csv2sql
+=======
+
+--------------------------------------------------
+import data from CSV files into an SQLite database
+--------------------------------------------------
+
+:Manual section: 1
+:Manual group: SlackBuilds.org
+:Date: |date|
+:Version: |version|
+
+SYNOPSIS
+========
+
+csv2sql [**-d** | **--database** *database*] [**-e** | **--encoding** *encoding* *INPUT*:*OUTPUT*] [**-f** | **--file** *filename*] [**-h** | **--help**] [**-t** | **-table** *table*] [**-v** | **--verbose**] [**-V** | **--version**]
+
+DESCRIPTION
+===========
+
+**csv2sql** is a Ruby script for importing comma-separated value files
+into SQLite.
+
+The destination table and database will automatically be created if
+they do not already exist.
+
+If the destination table already exists, then **csv2sql** assumes that
+it contains the same number of columns as the input data. The column
+names do not need to match.
+
+OPTIONS
+=======
+
+-d, --database DATABASE
+ Database to import into. Default is *csv2sql.db*.
+
+-e, --encoding INPUT:OUTPUT
+ Input and output encodings. Default is *UTF-8:UTF-8*.
+
+-f, --file FILENAME
+ CSV file to import. You can alternately read CSV data from standard input.
+
+-h, --help
+ Print built-in help message and exit.
+
+-t, --table TABLE
+ Table to import into. Default is the name of the file being imported from or *stdin* if CSV data is from standard input. Periods in the filename are replaced with underscores.
+
+-v, --verbose
+ Print verbose output.
+
+-V, --version
+ Print version number and exit.
+
+NOTE
+====
+
+**csv2sql** assumes the first line of CSV data is a header giving the
+column names. If your CSV file doesn't have column names (if the first
+line is just CSV data), you'll have to edit it and add the column
+names for **csv2sql** to work correctly with it.
+
+EXAMPLES
+========
+
+1. Import widgets.csv into the default table (widgets_csv) and database (csv2sql.db)::
+
+ csv2sql -f widgets.csv
+
+2. Import standard input into the "foo" table within the "bar.db" database::
+
+ cat widgets.csv | csv2sql -t foo -d bar.db
+
+3. Import products.csv and more-products.csv into the "products" table within the default database (csv2sql.db)::
+
+ csv2sql -f products.csv -t products
+ csv2sql -f more-products.csv -t products
+
+4. Export data from SQLite sorted by the "ProductName" column to output.csv::
+
+ sqlite3 -header -csv csv2sql.db "SELECT * FROM products ORDER BY ProductName" > output.csv
+
+COPYRIGHT
+=========
+
+**csv2sql** is open source software released under the MIT License. See::
+
+ http://www.opensource.org/licenses/MIT
+
+AUTHORS
+=======
+
+**csv2sql** was written by Matt Rideout.
+
+This man page written for the SlackBuilds.org project
+by B. Watson, and is licensed under the WTFPL.
+
+SEE ALSO
+========
+
+The csv2sql homepage: http://csv2sql.org/
diff --git a/system/csv2sql/slack-desc b/system/csv2sql/slack-desc
new file mode 100644
index 0000000000..2579914e05
--- /dev/null
+++ b/system/csv2sql/slack-desc
@@ -0,0 +1,19 @@
+# HOW TO EDIT THIS FILE:
+# The "handy ruler" below makes it easier to edit a package description.
+# Line up the first '|' above the ':' following the base package name, and
+# the '|' on the right side marks the last column you can put a character in.
+# You must make exactly 11 lines for the formatting to be correct. It's also
+# customary to leave one space after the ':' except on otherwise blank lines.
+
+ |-----handy-ruler------------------------------------------------------|
+csv2sql: csv2sql (create sqlite database from a CSV file)
+csv2sql:
+csv2sql: csv2sql is a Ruby script for importing comma-separated-value files
+csv2sql: into SQLite. It can read from a file or from standard input, and can
+csv2sql: create a new database or insert new data into an existing one. It can
+csv2sql: handle various character encodings; the default is UTF-8.
+csv2sql:
+csv2sql:
+csv2sql:
+csv2sql:
+csv2sql:
diff --git a/system/csv2sql/stdin.diff b/system/csv2sql/stdin.diff
new file mode 100644
index 0000000000..7e04eda97e
--- /dev/null
+++ b/system/csv2sql/stdin.diff
@@ -0,0 +1,19 @@
+diff -Naur csv2sql-0.1/csv2sql csv2sql-0.1.patched/csv2sql
+--- csv2sql-0.1/csv2sql 2015-03-07 13:20:09.000000000 -0500
++++ csv2sql-0.1.patched/csv2sql 2022-07-08 15:50:54.975335386 -0400
+@@ -24,13 +24,9 @@
+ else
+ error "the CSV file that you specified (#{file}) does not exist. Exiting."
+ end
+- # Otherwise, verify that standard input exists
++ # Otherwise, read from stdin
+ else
+- if $stdin.fcntl(Fcntl::F_GETFL, 0) == 0
+- verbose "Will read data from standard input."
+- else
+- error "you did not specify a CSV input file, or provide standard input. Exiting."
+- end
++ verbose "Will read data from standard input."
+ end
+ end
+