# Part Manager Installation

The parts manager is in development. All required functionality is not implemented.

## Requirements

Building and using the part manager requires the following packages:

PackageName | Description | Use
--- | --- | ---
autoconf | automatic configure script builder | Required
automake | A tool for generating GNU Standards-compliant Makefiles | Required
gcc | The GNU C compiler | Required
geda | GPL EDA – Electronics design software (metapackage) | Required
git-core | fast, scalable, distributed revision control system | Required
guile-1.8 | The GNU extension language and Scheme interpreter | Required
guile-1.8-dev | Development files for Guile 1.8 | Required
libgtk2.0-dev | Development files for the GTK+ library | Required
libtool | Generic library support script | Required
pkg-config | Manage compile and link flags for libraries | Required
xsltproc | XSLT command line processor | Required

Additionally, GParts requires a database for the back-end. Currently, GParts can use either MySQL, PostgreSQL, or SQLite.

### MySQL

In order to use MySQL, the packages listed below must be installed. The mysql-server package may not be required if configured to use a remote server.

PackageName | Description | Use
--- | --- | ---
libmysqlclient-dev | MySQL database development files | Required
mysql-client | MySQL database client | Required
mysql-server | MySQL database server | Required

### PostgreSQL

In order to use PostgreSQL, the following packages must be installed: (TODO: PostgreSQL not supported yet.)

PackageName | Description | Use
--- | --- | ---
libpq-dev | Header files for PostgreSQL library | Required
postgresql | Object-relational SQL database | Required

### SQLite

In order to use SQLite, the following packages must be installed:

PackageName | Description | Use
--- | --- | ---
libsqlite3-0 | SQLite 3 shared library | Required
libsqlite3-0-dbg | SQLite 3 debugging symbols | Optional
libsqlite3-dev | SQLite 3 development files | Required
sqlite3 | A command line interface for SQLite 3 | Required
sqlite3-doc | SQLite 3 documentation | Optional

Of course, installing all packages before building allows the application to use either database for the back-end.

## Building GParts from Source

If needed, obtain the source from the source repository.

    $ git clone git://git.geda-project.org/gparts
    Initialized empty Git repository in /home/username/Projects/gparts/.git/
    remote: Counting objects: 930, done.
    remote: Compressing objects: 100% (712/712), done.
    remote: Total 930 (delta 735), reused 269 (delta 207)
    Receiving objects: 100% (930/930), 745.34 KiB | 283 KiB/s, done.
    Resolving deltas: 100% (735/735), done.
    $ cd gparts
    $

In the top directory of the source package, execute the following commands. Support for PostgreSQL is incomplete, so use the configure option.

    $ ./autogen.sh
    $ ./configure --without-postgresql
    $ make

The install requires root privileges.

    $ sudo make install

Finally, test the executable.

    $ gparts

To ensure dynamically loaded modules for database support work, select Database→Connect… from the part manager menu. The combo box Database Type should so options for the various databases supported.

If no database modules appear in the combo box, it is likely the parts manager could not find the rc files. The parts manager needs to know the location of system-gafrc file. The parts manager will search for this file, but sometimes cannot locate it. Providing the following environment variable provides better results. For distributions using Debian packages, the system-gafrc file can be located with dpkg.

    $ dpkg -S system-gafrc
    libgeda-common: /etc/gEDA/system-gafrc

    $ GEDADATARC=/etc/gEDA
    $ export GEDADATARC

Additionally, the parts manager needs to know the location of the symbol library and scheme files.

    $ dpkg -S gschem.scm
    geda-gschem: /usr/share/gEDA/scheme/gschem.scm

    $ GEDADATADIR=/usr/share/gEDA
    $ export GEDADATADIR

## Database Creation

### MySQL

Install MySQL.

- Tested under 5.0.51a-3ubuntu5.1.

To create the database, enter MySQL command line mode as root and enter the SQL commands below. Placing the password in the command line could leave the password in the command line history. Using only the -p option will cause mysql to prompt for the password and avoid this situation. A different database name, other than gparts, can be specified by the user. Using different names, the user can create multiple GPart databases. Additionally, user accounts may need to be created.

    $ mysql -u root -p

    mysql> create database GParts;
    mysql> use GParts;
    mysql> grant all privileges on *.* to 'user'@'localhost' identified by 'password';

After creating the database, the base tables and part-specific tables must be created. All the SQL commands to perform these operations are included in the distributed files. Enter the following commands at the MySQL command line.

    mysql> source sql/mysql/create-basic.sql
    mysql> source sql/mysql/create-categories.sql
    mysql> source sql/mysql/create-discretes.sql
    mysql> source sql/mysql/create-passives.sql

Begin loading the database, starting with package data. The package data must be loaded before any parts.

    mysql> source data/packages.sql

The package includes a tool to parse the symbol libraries and generate an SQL file for import into the database. Run the tool at the shell prompt, then import the file from an MySQL prompt. The tool requires the root gEDA directory as the only parameter. Your gEDA root directory may be different than below. The symbol data must be loaded before any parts.

    $ tools/symbols.py /usr/share/gEDA >tmp/symbols.sql

    mysql> source tmp/symbols.sql

The package includes a script to generate some sample part data. Similar to the symbol tool, run the script at the shell prompt, then import the data at the MySQL prompt.

    $ data/parts-bourns.py >tmp/parts-bourns.sql

    mysql> source tmp/parts-bourns.sql

### PostgreSQL

TODO: Finish implementation

### SQLite

The source package contains a sample database in the location below. This database can be opened from directly within the parts manager.

- gparts/sql/sqlite/sample.db

If required, use the following command line to create a new database or recreate the sample database. In this example, the present working directory must be gparts/sql/sqlite.

    $ sqlite3 sample.db
    SQLite version 3.6.22
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>

After creating the database, read base and part specific tables into the database.

    sqlite> .read create-basic.sql
    sqlite> .read create-categories.sql
    sqlite> .read create-discretes.sql
    sqlite> .read create-passives.sql

Read sample symbols into the database.

    sqlite> .read symbols.sql

Exit the command line interface.

    sqlite> .exit

Read sample companies and packages into the database. The source distribution stores packages in XML. The distribution contains an XSLT stylesheet to convert XML into SQL for importing into SQLite. Use the following command line to perform this operation.

    $ xsltproc convert.xml ../../data/companies.xml | sqlite3 sample.db
    $ xsltproc convert.xml ../../data/packages.xml | sqlite3 sample.db

Read sample parts into the database.

    $ ../../data/parts-bourns.py >../../tmp/parts-bourns.xml
    $ xsltproc convert.xml ../../tmp/parts-bourns.xml | sqlite3 sample.db

For other sample parts, the data is not generated with a script.

    $ xsltproc convert.xml ../../tmp/rhom-discretes.xml | sqlite3 sample.db