Out put stream with dynamic location value/ file name? - progress-4gl

How to output a stream into a location that is getting dynamically..
For location getting statically can use
OUTPUT stream s1 to "D:\reports1.txt".
but if I want to get the value from screen, how?

DEF VAR cFileName AS CHAR NO-UNDO INITIAL "c:\temp\Bongo.txt".
DEF STREAM s1.
UPDATE cFileName FORMAT "x(30)".
OUTPUT STREAM s1 TO VALUE(cFileName).
OUTPUT STREAM s1 CLOSE.

Related

How can I display progress and track length in the video stream of LiquidSoap

I want to create a audio-video stream using Liquidsoap. And display the progess and total time of current track in the video. I wonder what is the best practice to achieve this. I am current using the following methods, in which:
Current progress is acquired with source.remaining function.
Total length is a global variable track_length, which is modified in on_track callback.
However, the current method has the following problems:
The return value of source.remaining does not change in a constant speed, as in the document metioned "estimation remaining time". In can be 19min, and suddenly jump to 19min20s, and then jump to 18min50. However, as the remaining time is less and less, the estimation becomes more accurate.
The track_length variable does get modified after the current track begins. However, the text drawing function which fetches the variable always get the initial value and never changed.
Thanks for your help!
Here is the relavant part of my script:
# Define the global variable to store the length of current track
track_length = 0
# Define the on_track callback which updates track_length
def process_metadata(metadata)
file_name = metadata["filename"]
track_length = file.duration(file_name)
end
# Define the audio source and hook on_track callback
audio = fallback([sequence([
single("/etc/liquidsoap/lssj1.mp3")
])])
audio = on_track(process_metadata, audio)
# Define the function which returns the text to render
def get_time()
"$(cur)/$(total)" % [("cur", string_of(source.remaining(audio))), ("total", string_of(track_length))]
end
# Create the video frame
video = fallback([blank()])
video = video.add_text.sdl(x=0, y=300, size=40, get_time, video)
There is no such term 'global variable' in liquidsoap
No assignment, only definitions. x = expr doesn't modify x, it just defines a new x. The expression (x = s1 ; def y = x = s2 ; (x,s3) end ; (y,x)) evaluates to ((s2,s3),s1).
Link: https://www.liquidsoap.info/doc-dev/language.html
So, you should use references:
Define:
track_length = ref 0
then modify it (note we also use int_of_float):
track_length := int_of_float(file.duration(file_name))
then get its value:
!track_length
I believe it will fix your problems

Can pysnmp return octectstring values only

I am doing a small script to get SNMP traps with PySnmp.
I am able to get the oid = value pairs, but the value is too long with a small information in the end. How can I access the octectstring only which comes in the end of the value. Is there a way other than string manipulations? Please comment.
OID =_BindValue(componentType=NamedTypes(NamedType('value', ObjectSyntax------------------------------------------------(DELETED)-----------------(None, OctetString(b'New Alarm'))))
Is it possible to get the output like the following, as is available from another SNMP client:
.iso.org.dod.internet.private.enterprises.xxxx.1.1.2.2.14: CM_DAS Alarm Traps:
Edit - the codes are :
**for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
target.write(str(val))**
On screen, it shows short, but on file, the val is so long.
Usage of target.write( str(val[0][1][2])) does not work for all (program stops with error), but the 1st oid(time tick) gets it fine.
How can I get the value from tail as the actual value is found there for all oids.
Thanks.
SNMP transfers information in form of a sequence of OID-value pairs called variable-bindings:
variable_bindings = [[oid1, value1], [oid2, value2], ...]
Once you get the variable-bindings sequence from SNMP PDU, to access value1, for example, you might do:
variable_binding1 = variable_bindings[0]
value1 = variable_binding1[1]
To access the tail part of value1 (assuming it's a string) you could simply subscribe it:
tail_of_value1 = value1[-10:]
I guess in your question you operate on a single variable_binding, not a sequence of them.
If you want pysnmp to translate oid-value pair into a human-friendly representation (of MIB object name, MIB object value), you'd have to pass original OID-value pair to the ObjectType class and run it through MIB resolver as explained in the documentation.
Thanks...
the following codes works like somwwhat I was looking for.
if str(oid)=="1.3.6.1.2.1.1.3.0":
target.write(" = str(val[0][1]['timeticks-value']) = " +str(val[0][1]['timeticks-value'])) # time ticks
else:
target.write("= val[0][0]['string-value']= " + str(val[0][0]['string-value']))

OpenEdge Dynamic TempTable

I am creating an application that accesses a database with many tables.
To make the coding easier and shorter, I am planning to make one procedure that either gets/sets the data dynamically or executes a procedure for specific data manipulations.
I've got something so far, but I'm kind of stuck now.
What I've done so far is made sure I can dynamically built a temp-table with the same schema as a database table I want to retrieve data from. I then query for a record and add it to the dynamic temp-table. Then this temp-table is passed as an output parameter.
What I want to do now is , when the user has changed the record, save that record dynamically. Therefore, I have to query the table dynamically and find the record the user wants to change. Actually the same as retrieving the record. But saving the changes made requires me to go through the input dynamic temp-table. How is this done?
The normal way of actions is like this:
- Get record by passing the table name and key. Then give the record to output parameter.
- Update record by getting dynamic temp-table as input parameter and then saving the changes from the correct record to the correct record. This second part is where I fail.
The code supplied here only does the first part, but the second part should be included into this code.
Code:
DEF VAR G-TableBuf AS HANDLE NO-UNDO.
DEF VAR G-TableBuf-Handle AS HANDLE NO-UNDO.
DEF VAR G-Query AS HANDLE NO-UNDO.
DEF VAR G-Table-FirNr AS INT NO-UNDO.
DEF VAR G-Qstring AS CHAR NO-UNDO.
DEF VAR G-Heeft-FirNr AS LOG NO-UNDO.
DEF VAR G-TempTable AS HANDLE NO-UNDO.
DEF VAR G-tt-Buffer AS HANDLE NO-UNDO.
DEF VAR G-MatchZone AS CHAR NO-UNDO.
DEF VAR G-prime-field AS CHAR NO-UNDO.
DEF VAR G-Zones-Buffer AS HANDLE NO-UNDO.
{lib/def_tt_ds_Errors.i}
DEF INPUT PARAMETER p_iFirnr AS INT NO-UNDO.
DEF INPUT PARAMETER p_iApplNr AS INT NO-UNDO.
DEF INPUT PARAMETER p_cUsrCd AS CHAR NO-UNDO.
DEF INPUT PARAMETER p_cAction AS CHAR NO-UNDO.
DEF INPUT PARAMETER p_cKeyCd AS CHAR NO-UNDO. /* Record key */
DEF INPUT PARAMETER p_cTable AS CHAR NO-UNDO. /* Table name */
DEF INPUT-OUTPUT PARAMETER TABLE-HANDLE hTT. /* INPUT-OUTPUT dynamic temp-table */
DEF OUTPUT PARAMETER DATASET FOR dsErrors.
RUN FindRecord.
RETURN.
PROCEDURE FindRecord :
/*------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/
DEF VAR i AS INT NO-UNDO.
CREATE TEMP-TABLE G-TempTable.
CREATE BUFFER G-TableBuf FOR TABLE p_cTable.
CREATE QUERY G-Query.
ASSIGN G-Table-FirNr = Get-Fir (p_cTable)
G-MatchZone = "kolom,Waarde"
G-heeft-firnr = FALSE
G-Zones-Buffer = BUFFER zones:HANDLE
G-TableBuf-Handle = G-TableBuf:HANDLE.
/* SCHEMA BUILDING CODE GOES HERE */
G-TempTable:TEMP-TABLE-PREPARE("tt" + p_cTable).
G-tt-Buffer = G-TempTable:DEFAULT-BUFFER-HANDLE.
G-tt-Buffer:EMPTY-TEMP-TABLE().
hTT = G-TempTable.
G-Qstring = "FOR EACH " + p_cTable.
G-Query:SET-BUFFERS(G-TableBuf).
G-Query:QUERY-PREPARE(G-Qstring).
G-Query:QUERY-OPEN().
G-Query:GET-NEXT().
REPEAT:
IF G-query:QUERY-OFF-END THEN
LEAVE.
G-tt-Buffer:BUFFER-CREATE.
G-tt-Buffer:BUFFER-COPY (G-TableBuf-Handle).
G-Query:GET-NEXT().
END.
END PROCEDURE.
Thanks in advance!
You need to study the ProDataset functionality, it'll make loading a TT and saving it's changed records back to the DB a lot easier.
To create a dynamic TT like a db table (at a high level), get the table's buffer handle, then go through it using b-handle:buffer-field(field-number):name to get a list of fields, and then use add-fields-from to create fields in the TT based on the db table.
Once you've got that, use the Prodataset "FILL" functionality to load data into it, and then pass the PDS back to the calling program for it to use.
when you're ready to save the data out, use the PDS functionity (save-row-changes) to save the changed records back to the database.
The process of loading and saving TT records is largely documented in the Prodatset set of docs. I highly recommend the 11.3 docs, as they're much improved over the prior version PDS docs.
This KB will also give you some ideas on how to build a dynamic TT like a db table. http://knowledgebase.progress.com/articles/Article/000045189?q=how+to+create+dynamic+temp-table&l=en_US&c=Product_Group%3AOpenEdge&type=Article__kav&fs=Search&pn=1
I used 2 different parameters for the dynamic temp-table, one for input and one for output. The rest I figured out myself. Thanks for your help guys!

Progress 4GL: Buffer handle attribute for all fields

I am fairly new to Progress and even newer to handles so apologies if I have missed anything obvious, I've looked online but am yet to find what I'm looking for.
I am running a dynamic query similar to the below, in this example after then query is run, the "age" field of the corrresponding record is displayed on screen, I understand how this is done from the buffer-field attribute-method, but my question is how do I display the entire record, is there an equivalent attribute method, or have I misunderstood something crucial?. Thank you for your time. :
def var tbl as character no-undo.
def var fld as character no-undo.
def var qh as handle no-undo.
def var bh as handle no-undo.
def var fh as handle no-undo.
assign tbl = "customer".
assign fld = "age".
create buffer bh for table tbl.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( "for each " + tbl + " where name = 'tom'" ).
qh:query-open.
do transaction:
qh:get-first( no-lock ).
fh = bh:buffer-field( fld ).
display fh:buffer-value.
end.
delete object bh.
delete object qh
There's no "easy" way to display the entire record in one statement the way you can with a static "DISPLAY table-name" statement. You can get the count of fields (buffer-handle:NUM-FIELDS) and then step through the individual fields and display their values using
DO i = 1 to bh:NUM-FIELDS:
DISPLAY bh:BUFFER-FIELD(i):BUFFER-VALUE WITH DOWN.
DOWN.
END.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( "for each " + tbl + " where name = 'tom'" ).
qh:query-open.
qh:GET-FIRST().
DO while qh:QUERY-OFF-END = False:
DO i = 1 TO bh:NUM-FIELDS:
display bh:BUFFER-FIELD (i):NAME STRING(bh:BUFFER-FIELD(i):BUFFER-VALUE) with down.
down.
END.
qh:GET-NEXT ().
END.

Read first X bytes of input stream in Scala

What is the most compact and scala-like way to read the first X bytes of an input stream to a buffer?
Wrap your java.io.InputStream in a scala.io.BufferedSource to get access the usual iterator operations:
val bufSrc = scala.io.Source.fromInputStream(inputStream)
val chars = bufSrc.take(X) // X being the number of bytes
Note that BufferedSource.take gives you an iterable of Char.
How about
Source.fromInputStream(inputStream).reader.read(..)
There are several read methods to accomplish what you require