1
/* $Id: loader.c,v 6.14 1999/05/25 16:21:20 kimelman Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information (NCBI)
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government do not place any restriction on its use or reproduction.
13
* We would, however, appreciate having the NCBI and the author cited in
14
* any work or product based on this material
16
* Although all reasonable efforts have been taken to ensure the accuracy
17
* and reliability of the software and data, the NLM and the U.S.
18
* Government do not and cannot warrant the performance or results that
19
* may be obtained by using this software or data. The NLM and the U.S.
20
* Government disclaim all warranties, express or implied, including
21
* warranties of performance, merchantability or fitness for any particular
24
* ===========================================================================
26
* Author: Michael Kimelman
28
* PubStruct DB Loader.
31
* --------------------------------------------------------------------------
33
* Revision 6.14 1999/05/25 16:21:20 kimelman
34
* bugfix : --checks & --load / didn't generate error message
36
* Revision 6.13 1998/11/20 22:46:00 kimelman
37
* fix loader return code
39
* Revision 6.12 1998/11/06 18:59:07 kimelman
40
* PubStruct loading transaction granularity changed
42
* Revision 6.11 1998/10/22 17:01:20 kimelman
43
* fix default dump directory
45
* Revision 6.10 1998/10/22 15:24:28 kimelman
46
* fixed path to check_loader & default dump area
48
* Revision 6.9 1998/10/05 17:50:20 kimelman
49
* processing fixed for "file not found" on load case
51
* Revision 6.8 1998/09/03 22:05:26 kimelman
52
* added cycles to retry on failes and
53
* wait for unhappy server to recover
55
* Revision 6.7 1998/08/05 21:12:35 kimelman
58
* Revision 6.6 1998/07/22 22:08:28 kimelman
59
* bugfix : check&create (./mmdb ==> $outdir)
61
* Revision 6.5 1998/07/16 20:00:33 kimelman
62
* pack & enforce options added
64
* Revision 6.4 1998/07/14 20:24:51 kimelman
65
* FT schema & smart load
67
* Revision 6.3 1998/05/14 16:11:17 kimelman
68
* Compression stuff added in debug mode.
69
* few bugs fixed, related to OpenServer/SQL Server switching
71
* Revision 6.2 1998/05/08 03:03:47 kimelman
74
* Revision 6.1 1998/04/03 20:25:21 kimelman
75
* PubStruct access code added to mmdbsrv
78
* ==========================================================================
82
#include "PubStructAsn.h"
85
#define LOAD_IN_STATE 1
87
static char MMDB[PATH_MAX];
88
static char outdir[PATH_MAX];
89
static char bindir[PATH_MAX];
90
static char *server=NULL;
91
static int state = -1;
92
static int enforce = 0;
95
remove_struct(int uid)
100
acc = PubStruct_lookup(server,uid,state);
102
acc = PubStruct_removeasn(server,acc);
116
sprintf(fname, "%s%ld.val.gz",MMDB,uid);
117
p = fopen(fname,"r");
121
sprintf(path, "gzip -dc %s%ld.val.gz",MMDB,uid);
122
/* sprintf(path, "gzip -dc %ld.val.gz",uid); */
123
p = popen(path,"rb");
127
sprintf(fname, "%s%ld.val",MMDB,uid);
128
p = fopen(fname,"r");
133
acc = PubStruct_load(p,(enforce?-state-1:state),server);
141
fprintf(stderr, "Can't open file: %s%d.val(.gz) ",MMDB,uid);
144
sprintf(fname, "%s%ld.txt",MMDB,uid);
145
p = fopen(fname,"r");
152
BiostrucPtr bsp = NULL;
155
aip = AsnIoOpen(fname,"r");
156
bsp=BiostrucAsnRead(aip,NULL);
159
aip = PubStruct_newasn(server,state,&acc);
160
commit = BiostrucAsnWrite(bsp,aip,NULL);
161
commit = PubStruct_closeasn(aip,commit);
163
if (!commit) acc = 0;
170
download(int uid, int pack)
178
sprintf(path,"%s/%ld.val",outdir,uid);
179
p = fopen(path,"wb");
183
sprintf(path, "gzip -c >%s/%ld.val.gz",outdir,uid);
184
p = popen(path,"wb");
190
acc = PubStruct_download(server,0,uid,p); /* can go throuth the open server */
193
acc = PubStruct_lookup(server,uid,state);
195
acc = PubStruct_download(server,acc,uid,p);
210
sprintf(cmd, "sh %s/loader_check.sh %s %ld.val.gz %s", bindir, MMDB, uid, outdir);
221
if(!CTLibInit(&clu,"MOZART_SYS10","PubStruct","kimelman","kmlmNu",0,NULL))
231
main(int argc, char**argv)
239
strcpy(MMDB,"/net/vaster/mmdb/mmdb/data/");
240
strcpy(outdir,"/tmp");
242
FILE *f = fopen(argv[0],"r");
244
if (f) /* great! - we have a direct path to binary program */
245
strcpy(bindir,argv[0]);
247
{ /* we should find the binary in the path */
249
sprintf(buf,"which %s", argv[0]);
252
fscanf(f,"%s",bindir);
254
f = fopen(bindir,"r");
258
fprintf(stderr,"Can't determine the path to binary - tried :\n%s\n%s\n",argv[0],bindir);
263
/* strip file name from path to get the dir name */
264
p = bindir + strlen(bindir);
265
while (p != bindir && *p != '/')
267
assert( p == bindir || *p == '/');
277
for (i = 1 ; i < argc ; i++)
279
if (strcmp(argv[i],"--remove")==0 || strcmp(argv[i],"-r")==0)
281
else if (strcmp(argv[i],"--load")==0 || strcmp(argv[i],"-l")==0)
283
else if (strcmp(argv[i],"--download")==0|| strcmp(argv[i],"-d")==0)
285
else if (strcmp(argv[i],"--checks")==0|| strcmp(argv[i],"-c")==0)
292
else if (strcmp(argv[i],"--verbose")==0 || strcmp(argv[i],"-v")==0)
295
ErrSetOptFlags(EO_LOGTO_STDERR);
297
else if (strncmp(argv[i],"--path=",strlen("--path="))==0)
298
strcpy(MMDB,argv[i]+strlen("--path="));
299
else if (strcmp(argv[i],"--pack")==0)
301
else if (strcmp(argv[i],"--enforce")==0)
303
else if (strncmp(argv[i],"--downpath=",strlen("--downpath="))==0)
304
strcpy(outdir,argv[i]+strlen("--downpath="));
305
else if (strncmp(argv[i],"--dbpath=",strlen("--dbpath="))==0)
306
server = argv[i]+strlen("--dbpath=");
307
else if (strncmp(argv[i],"--state=",strlen("--state="))==0)
308
state = atol(argv[i]+strlen("--state="));
313
if ( MMDB[strlen(MMDB)-1] != '/')
316
state = (mode & 1 ? LOAD_IN_STATE :0);
320
sprintf(shcmd," test -d %s || mkdir %s",outdir,outdir);
324
while(scanf("%d",&uid) != EOF)
332
printf("removing... ");
333
rc = remove_struct(uid);
339
{ printf("loading... "); rc = load(uid); }
341
{ printf("downloading... "); rc = download(uid,pack); }
343
{ check(uid); rc = -1 ; }
347
printf("slee-e-ep... ");
354
printf("%s ;\n",rc ?"ok":"FAILED");
362
printf("usage: %s [ --load | --remove | --download [ --checks | --pack ] ] \n"
363
" [ --path=mmdb_files_dir ] [ --downpath=dump_mmdb_files_dir ] \n"
364
" [ --state=<to_state> ] [ --verbose | -v ] [ --enforce ] \n"
365
" [ --dbpath=servername:DBname=username:password ]\n",