p4table.rb

Path: p4table.rb
Last Update: Tue Dec 07 12:17:00 GMT 2004

Introduction

Classes implementing a generic database model on top of plain text files stored in Perforce.

Every record consists of fields/values and may have associated files. The data for each record is stored as both a job and a text file. The text file is always called <id>/record and any associated files are also stored alongside the record file. i.e. <id>/file1 <id>/file2.

Each table name is a folder name and all records for that table are stored in text files under that folder. i.e. <table>/<id>/record

All column names must also be fields in the jobspec so you can search for records using "p4 jobs -e".

NOTE:When creating your jobspec, make sure that ALL field names are in lowercase. Ruby likes method names to be lowercase and it fits better as well as reducing scope for errors.

The job version of any record contains only the latest version of that record for searching purposes.

WARNING:This software is designed to have its OWN Perforce server to work with. DO NOT USE IT AGAINST AN EXISTING PERFORCE SERVER.

For a quick start, take a look at the P4Table class as all your tables should be derived from it and the Jobspec rules below.

Jobspec Rules

When creating your jobspec observe the following rules for any chance of success.

  • All fieldnames must be lowercase
  • The jobspec must contain a field called "job"
  • The jobspec must contain a field called "files" of type "text"
  • Make most fields optional - especially if you have more than one table
  • Do not use invalid preset values in your jobspec. i.e. a field which may only contain certain values but is deliberately initialised to an invalid value to force users to change it. P4/Ruby can’t handle jobspecs like this at the moment.

Jobspec Example

Below is the jobspec used for a FAX tracking application based on P4Ruby which should give you some idea of the possibilities.

 # A Perforce Job Spec Specification.
 #
 # Updating this form can be dangerous!
 # See 'p4 help jobspec' for proper directions.

 Fields:
        101 job word 32 required
        102 status select 10 required
        103 owner word 32 required
        104 modified_date date 20 always
        105 note text 0 optional
        106 sender line 32 optional
        107 fax_number line 32 optional
        108 files text 80 optional
        109 date_received date 20 once
        110 date_closed date 20 optional

 Values:
        status open/closed

 Presets:
        status open
        owner $user
        modified_date $now
        date_received $now

 Comments:

Required files

P4  

Constants

SEP = "\\"
NL = "\r\n"
SEP = "/"
NL = "\n"
DEPOT_ROOT_PATH = "//depot"

Classes and Modules

Class P4Global
Class P4RecFile
Class P4RecId
Class P4Record
Class P4Table

[Validate]