I'm trying to read a filepath from a config file and then read from that directory. I can't find a way to make it work though, because for some reason change-dir never goes to an absolute filepath. Here's a transcript of me trying to make it work on the CLI.
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! test
== %C/Users/thompson/Downloads/
>> change-dir test
** Access Error: Cannot open /C/rscratch/C/Users/thompson/Downloads/
** Near: change-dir test
It's failing because Rebol does not see
%C/Users/thompson/Downloads/
as an absolute path - it is missing the magic leading slash, so is seen as a relative path. Absolute path is this:
%/C/Users/thompson/Downloads/
So easy fix, if you are sure you do not have that leading slash:
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! join "/" test
There are many ways how get to an absolute Rebol file path,
the Rebol way
test: "test: %/C/Users/thompson/Downloads/"
select load test [test:]
the linux way
test: "test: /C/Users/thompson/Downloads/"
to-file trim find/tail test "test:"
the Windows way
test: "test: C:/Users/thompson/Downloads/"
to-rebol-file trim find/tail test "test:"
You will always get %/C/Users/thompson/Downloads/
Found an effective workaround.
changeDirAbsolute: func [input] [
change-dir %/
change-dir input
]
If anyone has a more elegant solution I'm open to hearing it!
In Rebol, because code is data and data is code, you can represent your .ini files by Rebol code. Incidentally, I and many others who are not Windows-centric prefer to use .cfg as the extension for these types of files. .ini refers to "initialization" which in many minds refers to the booting of a system, but could also refer to the starting of a program. .cfg is a little more precise in that it is a configuration file for a program.
With that said, try this instead:
test.cfg:
test: %/c/users/thompson/downloads
Then, you can simply do this from within your program:
>> do %test.cfg
That will automatically populate the filepath into the word 'test.
In non-Windows based operating systems, most often a filepath starts with a / when it refers to the root level of the filesystem. If it doesn't start with a /, it is a relative path (starting from the current directory).
I hope this helps!
Related
I'm using the File Should Exist keyword to check for an existing file in a List.
This is the high-level format:
Variables:
#{Files} /Desktop/Other/scooby.txt
... /Desktop/DummyFiles/daffy.txt
... %{CURDIR}/mickey.txt
Test Case:
Given File Should Exist ${Files[0]}
[...]
Output:
Setup failed:
Path '/Desktop/Other/scooby.txt' does not exist.
I'm not sure why this happens. The file name and filepath are correct. I also tried a bunch of different combinations (I copied the file over to the subdirectory this script is running from but that also doesn't work). I tried making the filepath a scalar variable instead of a List/array. Adding ".." in front of the file path doesn't work either. I've looked into "Glob pattern" but I don't think that's the issue either.
Always use absolute paths if in doubt. For example - /Desktop/Other/scooby.txt Does not point to any "meaningful" path even on windows because its lacking the the drive. On windows, using C:/Users/$yourlocalusername/Desktop/Other/scooby.txt might be working (replace $yourlocalusername with correct value)
Relying on relative paths (like in your example, 2 first ones are relative even thought you start with /, because in windows you still have a drive at the start) - you will need to ensure that working directory is set to a specific directory before you run your suite. Now, if you run your suite via IDE, current working directory might not be what you expect it to be so before you are familiar with how relative & absolute paths work - prefer to use absolute paths. See https://www.computerhope.com/issues/ch001708.htm - maybe that will clear out your issue.
You can either use ${CURDIR} or do not start the relative path with '/'.
I guess when starting with '/' , RF does not take this as relative path input and try to map the address from root directory i.e. C:
In below example, I have demonstrated both the approach, and it works fine for me.
*** Settings ***
Library OperatingSystem
Documentation Demonstrating File Exist keywords
*** Variables ***
#{Files} Data/VariableData/ConditionalFlows.robot
... Data/VariableData/testdata.robot
#{Files2} ${CURDIR}/Data/VariableData/ConditionalFlows.robot
... ${CURDIR}/Data/VariableData/testdata.robot
*** Test Cases ***
TS002-Check For File Existence
[Documentation] File exists
${File} File Should Exist ${Files}[0]
${File} File Should Exist ${Files2}[0]
I have input files:
Bob_1.fastq.gz
Bob_2.fastq.gz
Bob_3.fastq.gz
Bob_4.fastq.gz
Ron_1.fastq.gz
Ron_2.fastq.gz
Ron_3.fastq.gz
Ron_4.fastq.gz
I am running demultiplexing and trimming steps in one snakefile, like this:
workdir: "/path/to/dir/"
(SAMPLES,) =glob_wildcards('/path/to/dir/raw/{sample}.fastq.gz')
rule all:
input:
expand("demulptiplex/{sample}.fastq.gz", sample=SAMPLES),
expand("trimmed/{sample}.trimmed.fastq.gz", sample=SAMPLES)
rule sabre:
input:
infile="/path/to/dir/raw/{sample}.fastq.gz",
barcodefile= "files/{sample}.txt"
output:
unknownfile=temp("demulptiplex/unknown_barcode_{sample}.fastq.gz"),
shell:
"""
/Tools/sabre-master2/sabre se -f {input.infile} -b {input.barcodefile} -u {output.unknownfile}
"""
rule trimmomatic_se:
input:
r="{sample}.fastq.gz"
output:
r="trimmed/{sample}.trimmed.fastq.gz"
threads: 10
shell:
"""java -jar /Tools/Trimmomatic-0.36/trimmomatic-0.36.jar SE -threads {threads} {input.r} {output.r} ILLUMINACLIP:/Tools/Trimmomatic-0.36/adapters/TruSeq3-SE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36"""
The demultiplex output files are like this:
Bob_1_CL1.fastq.gz.... Bob_1_CL345.fastq.gz
Bob_2_CL1.fastq.gz.... Bob_1_CL248.fastq.gz
Ron_1_dad1.fastq.gz... Ron_1_dad67.fastq.gz
and so on
So,if I do not specify the demultiplex output file the program would create it by itself. My problem is how to specify/introduce a new wildcard from the output of the previous rule in the next trimming step, as the wildcards are different from initial sample now.
Wildcards just need to be consistent in a rule, not across the workflow. The issue here is that you have a rule generating 'unknown' outputs that you need to process further. For that you need to use checkpoints.
Read through the second block of code about aggregating. Your checkpoint will be demultiplexing and if you don't have any other steps, all will be your aggregate step that calls checkpoints.demultiplex.get. If you search for checkpoint on stackoverflow you will find lots of examples; it's a hard feature to use at first!
I am working on a PHP/Javascript project where I've nicely set up a build workflow. It involves testing, minifying, compressing into the final zip deliverable, and a whole lot of other nice stuff.
I want to build a task that fails when there are certain patterns in the source code. I would like to look for any print_r(), error_log(), var_dump(), etc functions, and halt the build process if there are any. Perhaps later I would like to check for things in Javascript or CSS so this is not only a PHP question.
I know it can be done with grunt-shell and grep but I'd like to know the following:
Are there any grunt plugins specific to this task? Ideally I would like to be able to specify a list of regexes per file type, and to set whether to continue or fail the build on pattern match.
How do others tackle the problem of double-checking the packaged source for the most common debug statements or other patterns?
Not a complete answer to my question, but I've recently come across this grunt plugin which is somewhat related. It removes console.log statements from JavaScript. Haven't tried it yet. Looks good. I still would like to know if there's something similar for PHP though.
http://grunt-tasks.com/grunt-remove-logging-calls/
Edit: Seeing as there's only tumbleweeds rolling in the wind here, I'm posting my workaround that's based on grunt-shell. However this is not what I was looking for. It's not perfect because it doesn't do proper syntax parsing:
shell: {
check_debug_prints: {
command: '(! (egrep -r "var_dump|print_r|error_log" --include=*.php src || egrep -r "console\.\w+|debugger;" --include=*.js src) ) || (echo "Debug prints in source - build aborted" && false )'
}
},
and
grunt.loadNpmTasks( 'grunt-shell' );
Edit 2: I finally found the exact grunt plugin I was looking for. It is grunt-search. There is a failOnMatch boolean option that lets you indicate if a particular regex pattern should cause the build to fail when found.
I am working on a Compass project and my final css output is huge so it needs to be be blessed .
I am using Codekit to compile my SCSS files, and it has the bless option for the less and sass files but unluckly this option seems to be not available for the compass projects (BTW there is no workaround to fix the problem https://github.com/bdkjones/CodeKit/issues/163)
Is there an alternative way to do that automatically after the compiling process? Is it possible to watch the css file with nodejs and then bless it?
====================================================
UPDATE
I am not using Codekit anymore I use Grunt to build the project assets and it works like a charm.
Well, it seems that using this reference you can simply do something like:
on_stylesheet_saved do |filename|
system('blessc ' + File.basename(filename))
end
after you have installed Bless.
What it does is simply attaching that event after you compile your Compass file :) Enjoy
This works for the regular compile command, but it doesn't work when you watch it. After Bless is completed the watch process ends.
I found that blessc just wouldn't execute, I'd get one of these two errors:
config.rb: No such file or directory - blessc (whatever filename)
or
env: node: No such file or directory
It turns out this is because blessc/node.js are installed in /usr/local/bin, and that is not in the PATH variable for ruby exec (/usr/bin:/bin:/usr/sbin:/sbin). The following code worked:
on_stylesheet_saved do |filename|
exec('PATH=$PATH:/usr/local/bin; blessc ' + filename + ' -f')
end
Edited to add: If after this you get errors saying that the files aren't css from bless, check if your absolute path to the file contains white space. You can escape the white space by doing the following:
on_stylesheet_saved do |filename|
exec('PATH=$PATH:/usr/local/bin; blessc ' + (filename.gsub! ' ', '\ ') + ' -f')
end
You can try the following code block, I've made couple of changes of Julian Xhokaxhiu answer:
on_stylesheet_saved do |filename|
begin
puts "Counting number of selector in :: " + filename
result = system('blessc',filename,'-f')
if not result
Kernel.exit(false)
else
puts "Blessed the file to support Older version of IE."
end
rescue Exception => e
puts "Please install bless.\nsudo npm install -g bless."
Kernel.exit(false)
end
end
I am new to the Grunt Task Runer. I'm trying to do some file matching in one of my configurations. With this file matching, I need ignore all of my test files, except for one. The one test file that I need to keep is named 'basic.test.js' In an attempt to do this, I currently have the following configuration:
files: [
'src/**/*.js',
'!src/**/*.test.js',
'src/root/basic.test.js'
]
At this time, I am still getting ALL of my tests. This means that my tests in the other test files are still being seen. I'm trying to confirm if I'm doing my globbing pattern correctly. Does my globbing pattern look correct for my scenario?
Thank you!
If you only want one test then there is no need to match and then unmatch all the others. Just include the one test:
files: [
'src/root/basic.test.js'
]