Glue for IPC now can be overridden via BeancountQueryInitialize()
Allow a single optional parameter to BeancountQueryInitialize() that overrides the default glue used for the IPC::Sharable glue.
This commit is contained in:
		
							parent
							
								
									f43e0000d1
								
							
						
					
					
						commit
						a5967d4cf9
					
				
					 2 changed files with 13 additions and 9 deletions
				
			
		|  | @ -11,7 +11,9 @@ our %BEANCOUNT_QUERY; | |||
| 
 | ||||
| my $IPC_GLUE = 'BeAn'; | ||||
| 
 | ||||
| sub BeancountQueryInitialize { | ||||
| sub BeancountQueryInitialize (;$) { | ||||
|   $IPC_GLUE = $_[0] if (defined $_[0]); | ||||
|   die "Glue must be exactly four characters" unless defined $IPC_GLUE and length($IPC_GLUE) == 4; | ||||
|   my %options = (create    => 0, exclusive => 0, mode      => 0600, destroy   => 0); | ||||
|   tie %BEANCOUNT_QUERY, 'IPC::Shareable', $IPC_GLUE, { %options } or | ||||
|     die "BEANCOUNT_QUERY: tie failed: is the goffy beancount server running?\n"; | ||||
|  |  | |||
|  | @ -28,13 +28,13 @@ $ENV{PAGER} = "/usr/bin/cat"; | |||
| 
 | ||||
| my $BEANCOUNT_QUERY_CMD = "/usr/bin/bean-query"; | ||||
| 
 | ||||
| my($VERBOSE, $BEANCOUNT_DIR, $LOAD_FILE, $BRANCH_NAME, $FIFO_DIR) = (0, undef, undef, undef, undef); | ||||
| my($VERBOSE, $BEANCOUNT_DIR, $LOAD_FILE, $BRANCH_NAME, $FIFO_DIR, $CLEAR_FILES, $GLUE) = (0, undef, undef, undef, undef, 1, 'BeAn'); | ||||
| 
 | ||||
| GetOptions("verbose=i" => \$VERBOSE, "beancountDir=s" => \$BEANCOUNT_DIR, | ||||
| GetOptions("verbose=i" => \$VERBOSE, "beancountDir=s" => \$BEANCOUNT_DIR, 'glue=s' => \$GLUE, 'clearFiles!', \$CLEAR_FILES, | ||||
|            "loadFile=s" => \$LOAD_FILE, "branchName=s" => \$BRANCH_NAME, 'fifoDir=s' => \$FIFO_DIR); | ||||
| 
 | ||||
| sub UsageAndExit($) { | ||||
|   print STDERR "usage: $0 --loadFile=/path/to/file.beancount --beancountDir=/path/to/beancountdir --fifoDir=/path/to/directory/for/fifos [ --branchName=BRANCH_NAME --verbose=N ]\n"; | ||||
|   print STDERR "usage: $0 --loadFile=/path/to/file.beancount --beancountDir=/path/to/beancountdir --fifoDir=/path/to/directory/for/fifos [ --glue=FOUR_CHAR_STRING --branchName=BRANCH_NAME --verbose=N ]\n"; | ||||
|   print STDERR "\n  $_[0]\n"; | ||||
|   exit 2; | ||||
| } | ||||
|  | @ -48,6 +48,9 @@ chdir $BEANCOUNT_DIR; | |||
| UsageAndExit("/path/to/file.beancount must a relative path to a file that exists in $BEANCOUNT_DIR") | ||||
|   unless (defined $LOAD_FILE and -r $LOAD_FILE); | ||||
| 
 | ||||
| UsageAndExit("glue must be at exactly four characters") | ||||
|   unless (defined $GLUE and length($GLUE) == 4); | ||||
| 
 | ||||
| my($tempRepository, $tempRepositoryDirectory); | ||||
| 
 | ||||
| sub CleanupEvertything { | ||||
|  | @ -103,7 +106,6 @@ sub CheckUpstreamAndPull { | |||
|         "so give up entirely on trying to make this work."); | ||||
|   } | ||||
| } | ||||
| my $glue = 'BeAn'; | ||||
| my %options = ( | ||||
|                create    => 'yes', | ||||
|                exclusive => 0, | ||||
|  | @ -111,13 +113,13 @@ my %options = ( | |||
|                destroy   => 'yes', | ||||
|       ); | ||||
| my %query; | ||||
| tie %query, 'IPC::Shareable', $glue, { %options } or | ||||
|   die "server: tie failed for $glue\n"; | ||||
| tie %query, 'IPC::Shareable', $GLUE, { %options } or | ||||
|   die "server: tie failed for $GLUE\n"; | ||||
| 
 | ||||
| %query = (); | ||||
| 
 | ||||
| my %beancountData; | ||||
| tie %beancountData, 'IPC::Shareable', $glue, { %options } or | ||||
| tie %beancountData, 'IPC::Shareable', $GLUE, { %options } or | ||||
|   die "server: tie failed\n"; | ||||
| 
 | ||||
| my ($currentFormat, $runningBeanQuery); | ||||
|  | @ -132,7 +134,7 @@ sub StartRunningBeanQuery { | |||
|     $tempRepository->run(clean => '-fx', { quiet => 1 }); | ||||
|     $tempRepository->run(reset => '--hard', { quiet => 1 }); | ||||
|     $tempRepository->run(clean => '-fx', { quiet => 1 }); | ||||
|   } else { | ||||
|   } elsif ($CLEAR_FILES) { | ||||
|     my(@findCmd) = ("/usr/bin/find", '.', '-name', '*.picklecache'); | ||||
|     if ($VERBOSE > 4) { | ||||
|       print STDERR "Cleared the following picklecache files (none listed means none existed)...\n"; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn