i can read this format text(e.g. id.txt) file:
- 1BCF-2982 -- Installing Driver
- 1BCF-2982 -- Driver Installed
- (Testing Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card)
- Executing Test -- MEID hex value
- Extended test data -- MEID:0xA1000013B8F66E
- Executing Test -- IMEI decimal value
- Extended test data -- IMEI:355023040845227
- Executing Test -- ICCID decimal value
- (Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card Test Results)
or below format id.txt file
- 1BCF-2982 -- Installing Driver
- 1BCF-2982 -- Driver Installed
- (Testing Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card)
- Extended test data -- MEID:0xA1000013B8F66E
- Extended test data -- IMEI:355023040845227
- (Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card Test Results)
this is my way, build meid.sed and imei.sed
/MEID/{
s/^.*:0x([-0-9a-zA-Z]+)/set meid=\1/p;
}
and imei.sed
/IMEI/{
s/^.*:([-0-9a-zA-Z]+)/set imei=\1/p;
}
Could you talk me simple way, the output will look like this:
set meid=A1000013B8F66E
set imei=355023040845227
thanks!
$ sed -nr '/.*(MEID|IMEI):(0x)?([0-9A-F]+)/s//set \L\1\E=\3/p' id.txt
set meid=A1000013B8F66E
set imei=355023040845227
dirty and quick awk oneliner works with your examples:
awk -F' -- |:' 'NF>2{print "set "tolower($2)"="$3}' yourFile
test with example1:
kent$ echo "- 1BCF-2982 -- Installing Driver
- 1BCF-2982 -- Driver Installed
- (Testing Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card)
- Extended test data -- MEID:0xA1000013B8F66E
- Extended test data -- IMEI:355023040845227
- (Wireless 5630 (EVDO-HSPA) Mobile Broadband Mini-Card Test Results)
"|awk -F' -- |:' 'NF>2{print "set "tolower($2)"="$3}'
set meid=0xA1000013B8F66E
set imei=355023040845227
You can achieve the same with this command
cat <your input file> | grep -E "MEID:|IMEI:" | awk '{print $NF;}' | tr ':' '=' | awk '{print "set " $0;}'
either you can run it from command prmpt or put the same in .sh file and run it
Related
I run Busybox version 1.23.2. The default shell is Bourne shell. The auto completion works half: Suppose here are two directories a123 and a120. I type cd a and TAB and I just get:
# cd a
a123/ a120/
# cd a
I cannot tab through the possibilities with TAB. I have to complete the full name by hand.
I tried to install bash-completion but I get only:
# opkg list | grep bash-completion
kmod-bash-completion - 20+git0+d9c7175859-r0 - Tools for managing Linux kernel modules
libdbus-glib-1-bash-completion - 0.104-r0 - High level language (GLib) binding for D-Bus
libglib-2.0-bash-completion - 1:2.44.0-r0 - A general-purpose utility library
util-linux-bash-completion - 2.26.1-r0 - A suite of basic system administration utilities
What can I do so that I can tab through the possibilities?
I have an iOS project written by Swift 3.0 with CocoaPods. I've configured Gitlab CI for this project and it works perfectly. This is my .gitlab-ci.yml file:
stages:
- build
build_project:
stage: build
script:
- rm -rf Pods;rm -rf MyProject.xcworkspace;rm -rf MyProject.xcodeproj/project.xcworkspace
- pod install
- xcodebuild clean -workspace MyProject.xcworkspace -scheme MyProject | xcpretty
- xcodebuild test -workspace MyProject.xcworkspace -scheme MyProject -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.2' | xcpretty -s
tags:
- ios
- lunchdot
I can't see code coverage for this project in my Gitlab repo. At the moment a coverage column for all my builds is empty. I tried to set Test coverage parsing in CI/CD Pipelines Gitlab settings, but it hadn't any effect because I don't know regex for Swift. Is it possible to set up code coverage for Swift project in Gitlab CI? How can I do this?
So, I tried a million ways to do it and the issue turned out to be xcpretty. After I removed it I started getting consistent results with my gitlab ci coverage data. If you still do not want to get tons of data you do not care about, you can use -quiet in your gitlab yams file. I will post it all though, so keep reading.
One still needs an external tool for coverage analysis - xcov seems to not be available anymore so I used slather. Worked like a charm.
These are the steps:
1) Get slather.
2) Get your .slather.yml file straightened out. Mine looks like the following (YourApp is the name of your app obviously):
# .slather.yml
coverage_service: cobertura_xml
xcodeproj: ./YourApp.xcodeproj
workspace: ./YourApp.xcworkspace
scheme: YourApp
source_directory: ./YourApp
output_directory: path/to/xml_report
ignore:
- "**/Pods/*"
- "thirdparty/*"
- "./Scripts/*"
- "**/3rdParty/*"
- "../**/Developer/*"
- "**/libraries/*"
- "Module-Core/*"
- "Module-Components/*"
- "**/AppUnitTests/*"
You can get the test output as html, xml, in codecov.io, etc, totally up to you. Check out the slather GitHub page to see the possible ways of doing that. But for the current issue, all we need is slather reporting in the command line so gitlab can pick it up. That is where properly setting up the gitlab yaml file comes in.
3) Set up the .gitlab-ci.yml file. Mine looks like this:
stages:
- build
build_project_1:
stage: build
script:
- xcodebuild clean -workspace YourApp.xcworkspace -scheme YourApp -quiet
- xcodebuild test -workspace YourApp.xcworkspace -scheme YourApp -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.3.1' -enableCodeCoverage YES -quiet
after_script:
- slather coverage -s
only:
- master
4) Next step is to:
Go to your gitlab page/profile or whatever you call it
Go to Settings and then Pipelines
Scroll down to Test coverage parsing and add this regex expression there: \d+\%\s*$
And that is it. All you need to do is invoke a build.
Since Xcode 9.3 Apple provides xccov, so here is a solution using this, that does not rely on third party dependencies (and does not care if you use xcpretty, -quiet etc.)
Overview of xccovreport and xccov
When your Scheme has test coverage enabled (or when you pass -enableCodeCoverage YES to xcodebuild), an .xccovreport file is created. It contains the coverage percentages that you can see in Xcode UI.
The file is located in:
(for Xcode 9)
/Users/somename/Library/Developer/Xcode/DerivedData/MyApp-airjvkmhmywlmehdusimolqklzri/Logs/Test/E387E6E7-0AE8-4424-AFBA-EF9FX71A7E46.xccovreport
(for Xcode 10)
/Users/somename/Library/Developer/Xcode/DerivedData/MyApp-airjvkmhmywlmehdusimolqklzri/Logs/Test/Test-MyApp-2018.10.12_20-13-43-+0100.xcresult/action.xccovreport
(unless you specify a different folder in xcodebuild via -derivedDataPath)
Note: In Xcode 10, the .xccovreport file location is printed out in console after test finishes, but Xcode 9 does not do this. In any case, relying on this is probably not a good idea, as it might be silenced (e.g. by xcpretty)
The file isn't a plain text and to view it you have to call:
xcrun xccov view <path_to_xccovreport_file>
Which will output the report.
(You can pass --json for JSON report)
What we need to do
We want to be able to parse the file and print out the total percentage (so then GitLab can pick this up and use it in the dashboard).
There are a couple of challenges:
- Firstly we need to find out the file path of the xccovreport which contains random strings (in two places)
- Then we need to parse the file (using some regular expressions) and extract the total percentage.
The script
Here's what I am using (any improvement suggestions welcome, as I am not a bash expert):
#!/bin/bash
#1
# Xcode 10
TEST_LOGS_DIR=`xcodebuild -project MyApp.xcodeproj -showBuildSettings | grep BUILD_DIR | head -1 | perl -pe 's/\s+BUILD_DIR = //' | perl -pe 's/\/Build\/Products/\/Logs\/Test/'`
TEST_RESULTS_DIR=`ls -t $TEST_LOGS_DIR | grep "xcresult" | head -1`
TEST_COV_REPORT_FILENAME=`ls "$TEST_LOGS_DIR/$TEST_RESULTS_DIR/1_Test" | grep "xccovreport"`
TEST_COV_REPORT_FULL_PATH="$TEST_LOGS_DIR/$TEST_RESULTS_DIR/1_Test/$TEST_COV_REPORT_FILENAME"
# Xcode 9
# TEST_LOGS_DIR=`xcodebuild -project MyApp.xcodeproj -showBuildSettings | grep BUILD_DIR | head -1 | perl -pe 's/\s+BUILD_DIR = //' | perl -pe 's/\/Build\/Products/\/Logs\/Test/'`
# TEST_COV_REPORT_FILENAME=`ls $TEST_LOGS_DIR | grep "xccovreport"`
# TEST_COV_REPORT_FULL_PATH="$TEST_LOGS_DIR/$TEST_COV_REPORT_FILENAME"
# More general recursive search. Perhaps less likely to fail on new Xcode versions. Relies on filepaths containing timestamps that sort alphabetically correctly in time
# TEST_LOGS_DIR=`xcodebuild -project MyApp.xcodeproj -showBuildSettings | grep BUILD_DIR | head -1 | perl -pe 's/\s+BUILD_DIR = //' | perl -pe 's/\/Build\/Products/\/Logs\/Test/'`
# TEST_COV_REPORT_FULL_PATH=`find $TEST_LOGS_DIR -name '*.xccovreport' | sort -r | head -1`
#2
TOTAL_XCTEST_COVERAGE=`xcrun xccov view $TEST_COV_REPORT_FULL_PATH | grep '.app' | head -1 | perl -pe 's/.+?(\d+\.\d+%).+/\1/'`
#3
echo "TOTAL_XCTEST_COVERAGE=$TOTAL_XCTEST_COVERAGE"
What it does
#1 - gets the BUILD_DIR and then manipulates the path to get to the xccovreport file. Comment / uncomment the block for your version of Xcode.
#2 - We start with the full report as text. grep '.app' takes only the lines that contain .app. This is guaranteed to exist, because there is a line that reports the total coverage and contains MyApp.app. There will be multiple matches, but the first match will always be the overall total codecov score. So we use head -1 to take that first line of the grep result.
Now we have a line that looks like this:
MyApp.app 12.34% (8/65)
We use a perl regex to take only the “12.34%” part.
#3 - We simply print out the result (together with the variable name to make it easier to locate later in GitLab CI)
How to use
Replace MyApp.xcodeproj with your correct value
Make sure the correct logic is applied in step #1 (Xcode 9 / Xcode 10 / Generalized recursive search)
Save to a printCodeCov.sh file in the root of your project.
Make the file executable chmod +x printCodeCov.sh
In your .gitlab-ci.yml file, add a line to the script that says - ./printCodeCov.sh
In your GitLab Pipeline Settings, set the Test coverage parsing to TOTAL_XCTEST_COVERAGE=(.+)%
Notes
This does not use the --json format of xccov. For that version, see below.
This solution might be fragile, because of multiple assumptions about folder locations and report format
I use perl instead of sed because the latter was too difficult (BSD/GNU differences, regex limitations etc).
JSON version
If you'd rather use the JSON report (from xccov), then in the script you need something like this:
# Xcode 10
COV_NUMBER_FRACTION=`xcrun xccov view --json $TEST_COV_REPORT_FULL_PATH | perl -pe 's/.+?\.app.+?"lineCoverage":([^,]+).+/\1/'`
# Xcode 9
# COV_NUMBER_FRACTION=`xcrun xccov view --json $TEST_COV_REPORT_FULL_PATH | perl -pe 's/.+"targets"[^l]+lineCoverage":([^,]+),.+/\1/'`
COV_NUMBER_PERCENTAGE=`bc <<< $COV_NUMBER_FRACTION*100`
TOTAL_XCTEST_COVERAGE=`printf "%0.2f%%\n" $COV_NUMBER_PERCENTAGE`
I am attempting to send across a DICOM file to a DicomProxy, which is meant to convert the file and output to another server. However when executing the following command:
bin/storescu -c DICOMPROXY#XX.XXX.XXX.XX:XXXX ../example/XXXXXX.dcm
in the terminal, the following message appears.
Connected to DICOMPROXY in 35ms
org.dcm4che3.net.NoPresentationContextException: No Presentation Context for Abstract Syntax: 1.2.840.10008.5.1.4.1.1.2 - CT Image Storage negotiated
at org.dcm4che3.net.Association.pcFor(Association.java:795)
at org.dcm4che3.net.Association.cstore(Association.java:829)
at org.dcm4che3.net.Association.cstore(Association.java:823)
at org.dcm4che3.tool.storescu.StoreSCU.send(StoreSCU.java:483)
at org.dcm4che3.tool.storescu.StoreSCU.sendFiles(StoreSCU.java:387)
at org.dcm4che3.tool.storescu.StoreSCU.main(StoreSCU.java:296)
09:49:20,037 INFO - STORESCU->DICOMPROXY(1) << A-RELEASE-RQ
09:49:20,037 DEBUG - STORESCU->DICOMPROXY(1): enter state: Sta7 - Awaiting A-RELEASE-RP PDU
09:49:20,038 INFO - STORESCU->DICOMPROXY(1) >> A-RELEASE-RP
09:49:20,039 INFO - STORESCU->DICOMPROXY(1): close Socket[addr=/XX.XXX.XXX.XX,port=XXXX,localport=50596]
09:49:20,039 DEBUG - STORESCU->DICOMPROXY(1): enter state: Sta1 - Idle
Sent 0 objects (=0MB) in 0.022s (=0MB/s)
Does anybody know the reason why the file will not send?
Thanks.
Okay I figured the issue out, I was doing the syntax for storescu incorrectly. it should be like so:
bin/storescu -c DICOMPROXY#XX.XXX.XXX.XX:XXXX -b AET:PORT ../example/XXXXXX.dcm
Where -c represents the destination and -b represents the modality.
I need to create an echo device for software tests under Raspbian.
The aim is a device, that returns everything. E.g. if I would send some data to a device (ls > /dev/tty30), I need this data back from this (or an equal) device.
Is there already a possibility out-of-the-shelf inside Raspian? (e.g. an echo device)
Can I create such a device by an serial null modem simulation?
Raspbian sure supports such behaviour:
root#raspberrypi:/root# mkfifo /dev/tty100
root#raspberrypi:/root# cat < /dev/tty100 |cat > /dev/tty100&
[1] 19024
root#raspberrypi:/root# echo hi > /dev/tty100
root#raspberrypi:/root# cat /dev/tty100
hi
^C
I want to create web service for my Phonegap Android application which will further call progress 4GL 91.D procedure.
Does any one knowy idea how to create web service for this.
That will be a struggle. You CAN create a server that listens to a socket but you will have to handle everything yourself!
Look at this example.
However, you are likely better off writing the webservice in a language with a better support and then finding another way of getting the data out of the DB. If youre really stuck with a 10+ year old version you really should consider migrating to something else.
You don't have to upgrade everything -- you could just obtain a license for a version 10 client. V10 clients can connect to v9 databases (the rule is that the client can be up to one major release higher) so you could use that to build a SOAP service. Or you could get a v10 "webspeed" license.
Or you could write a simple enough CGI wrapper to some 4GL code if you have those sorts of skills. I occasionally toss together something like this:
#!/bin/bash
#
LOGFILE=/tmp/myservice.log
SVC=sample
# if a FIFO does not exist for the specified service then create it in /tmp
#
# $1 = direction -- in or out
# $2 = unique service name
#
pj_fifo() {
if [ ! -p /tmp/$2.$1 ]
then
echo `date` "Creating FIFO $2.$1" >> ${LOGFILE}
rm -f /tmp/$2.$1 >> ${LOGFILE} &2>&1
/bin/mknod -m 666 /tmp/$2.$1 p >> ${LOGFILE} &2>&1
fi
}
if [ "${REQUEST_METHOD}" = "POST" ]
then
read QUERY_STRING
fi
# header must include a blank line
#
# we're returning XML
#
echo "Content-type: text/xml" # or text/html or text/plain
echo
# debugging echo...
#
# echo $QUERY_STRING
#
# echo "<html><head><title>Sample CGI Interface</title></head><body><pre>QUERY STRING = ${QUERY_STRING}</pre></body></html>"
# ensure that the FIFOs exist
#
pj_fifo in $SVC
pj_fifo out $SVC
# make the request
#
echo "$QUERY_STRING" > /tmp/${SVC}.in
# send the response back to the requestor
#
cat /tmp/${SVC}.out
# all done!
#
echo `date` "complete" >> ${LOGFILE}
Then you just arrange for a background session to be reading /tmp/sample.in:
/* sample.p
*
* mbpro dbname -p sample.p > /tmp/sample.log 2>&1 &
*
*/
define variable request as character no-undo.
define variable result as character no-undo.
input from value( "/tmp/sample.in" ).
output to value( "/tmp/sample.out" ).
do while true:
import unformatted request.
/* parse it and do something with it... */
result = '<?xml version="1.0"?>~n<status>~n'.
result = result + "ok". /* or whatever turns your crank... */
result = result + "</status>~n".
end.
When input arrives parse the line and do whatever. Spit the answer back out to /tmp/sample.out and loop. It's not very fancy but if your needs are modest it is easy to do. If you need more scalability, robustness or security then you might ultimately need something more sophisticated but this will at least let you get started prototyping.