For testing purpose, I used Xvfb.
Today, I want to do some test with wmctrl commmand. I do some test in python like this :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()
In this test, wmctrl says :
Cannot get client list properties.
(_NET_CLIENT_LIST or _WIN_CLIENT_LIST)
I think, it's normal because I haven't any window manager attach to my Xvfb.
How to start a windows manager (Enlighenment should be good for my case) to manage only Xvfb ?
After some days of works, I can answer myself. Solution is easy as possible : just start windows manager with variable DISPLAY set. So in my python script, I just do :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
# start windows manager
pWM = subprocess.Popen( ["/usr/bin/enlightenment_start", ] )
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()
I tried add relation to neo4j and it doesn't work correctly... (this relations don't exist after executing script)...
my script (i run it in this way: Neo4jShell.bat -file gf.txt) :
CREATE (j1 { lc :1, ln: 'ln1' });
CREATE (j2 { lc :2, ln: 'ln2' });
CREATE (j3 { lc :3, ln: 'ln3' });
...
CREATE (p1 { pc : 1, pn : 'pn1'});
CREATE (p1 { pc : 2, pn : 'pn2'});
CREATE (p1 { pc : 3, pn : 'pn3'});
...
CREATE (j1)-[:F]->(p1);
CREATE (j2)-[:F]->(p2);
CREATE (j3)-[:F]->(p3);
Are you seeing any mistakes in my big script ?
Once you end your statement with a semicolon, you can't refer to the identifiers/nodes created in that statement anymore. It's not going to know what (j1) is, so it's going to create a new node (j1) with no properties.
Update:
Either remove your semicolons, or you'll need to MATCH the nodes again.
I'm trying to build an Active Appearance Model like in this guide.
But some of the comments sounds to me abstract and incomprehensible. So can you upload the entire set of files needed to create a model or send a link which has it. Thanks and sorry for my english!
When you download the aam project from Tim Cootes website it should have everything you need to get started.
http://www.isbe.man.ac.uk/~bim/software/am_tools_doc/
I recommend to run windows binary files with "wine" on linux. The linux binary files depend on some outdated libraries that require some effort to install properly.
The project has a few key folders: images, points, models, win_bin. "images" is the folder with image files and their corresponding .pts files go to "points" folder.
"models" folder contains configuration .smd files that you will use to build your model. The example of the accompanying smd file looks as follows:
~/Documents/am_tools/models$ cat tim_face.smd
// List of images + parameters required to define type of model
// Note: List excludes images in the separate test set (tim_face_test.smd)
model_name: tim_face
model_dir: ./
parts_file: face
image_dir: ../images/
points_dir: ../points/
shape_aligner: align_similar_2d
shape_modes: { min: 0 max: 30 prop: 0.98 }
tex_modes: { min: 0 max: 40 prop: 0.99 }
combined_modes: { min: 0 max: 30 prop: 0.99 }
params_limiter: mdpm_box_limits
{
sd_limits: 3
}
n_pixels: 10000
colour: Grey // Alternatives: Grey,RGB,...
// Texture Sampler can be tri_raw, tri_edge...
tex_sampler: vapm_triangle_sampler<vxl_byte>
tex_aligner: align_linear_1d
// shape_wts define how to compute relative scaling of shape & tex.
// shape_wts can be `EqualVar', `EqualEffect',...
shape_wts: EqualVar
// tex_model defines type of model to represent texture statistics, eg: pca, pca+haar1d
tex_model: pca
// Image Pyramid Builder can be gauss_byte, gauss_float, grad_float ...
pyr_builder: gauss_byte
points_pyr_builder: Same
max_im_pyr_levels: 5
// Levels of multi-res model to build :
min_level: 0
max_level: 4
// Details of points : images
training_set:
{
107_0764.pts : 107_0764.jpg
107_0766.pts : 107_0766.jpg
107_0779.pts : 107_0779.jpg
107_0780.pts : 107_0780.jpg
107_0781.pts : 107_0781.jpg
107_0782.pts : 107_0782.jpg
107_0784.pts : 107_0784.jpg
107_0785.pts : 107_0785.jpg
107_0786.pts : 107_0786.jpg
107_0787.pts : 107_0787.jpg
107_0788.pts : 107_0788.jpg
107_0789.pts : 107_0789.jpg
107_0790.pts : 107_0790.jpg
107_0791.pts : 107_0791.jpg
107_0792.pts : 107_0792.jpg
}
Just make sure that the listed .pts and .jpg files are present in you images and points folders. Next run the am_build_apm.exe/am_build_aam.exe commands:
~/Documents/am_tools/win_bin$ wine am_build_apm ../models/tim_face.smd
This will create tim_face.apm file in the win_bin folder. The created model can now be viewed by running:
~/Documents/am_tools/win_bin$ wine am_view_apm.exe
and opening ~/Documents/am_tools/models/tim_face.smd file in the application menu.
Now play with different parameters in .smd file, try to add your own images with pts files, I think BioID database has a few hundred images annotated with .pts files.
http://www.bioid.com/index.php?q=downloads/software/bioid-face-database.html
What is the easiest method for joining/merging all files in a folder (tab delimited) into a single file? They all share a unique column (primary key). Actually, I only need to combine a certain column and link on this primary key, so the output file would contain a new column for each file. Ex:
KEY# Ratio1 Ratio2 Ratio3
1 5.1 4.4 3.3
2 1.2 2.3 3.2
etc....
There are many other columns in each file that I don't need to combine in the output file, I just need these "ratio" columns linked by the unique key column.
I am running OS X Snow Leopard but have access to a few Linux machines.
use the join(1) utility
I actually spent some time learning Perl and solved the issue on my own. I figured I'd share the source code if anyone has a similar problem to solve.
#!/usr/bin/perl -w
#File: combine_all.pl
#Description: This program will combine the rates from all "gff" files in the current directory.
use Cwd; #provides current working directory related functions
my(#handles);
print "Process starting... Please wait this may take a few minutes...\n";
unlink"_combined.out"; #this will remove the file if it exists
for(<./*.gff>){
#file = split("_",$_);
push(#files, substr($file[0], 2));
open($handles[#handles],$_);
}
open(OUTFILE,">_combined.out");
foreach (#files){
print OUTFILE"$_" . "\t";
}
#print OUTFILE"\n";
my$continue=1;
while($continue){
$continue=0;
for my$op(#handles){
if($_=readline($op)){
my#col=split;
if($col[8]) {
$gibberish=0;
$col[3]+=0;
$key = $col[3];
$col[5]+=0; #otherwise you print nothing
$col[5] = sprintf("%.2f", $col[5]);
print OUTFILE"$col[5]\t";
$continue=1;
} else {
$key = "\t";
$continue=1;
$gibberish=1;
}
}else{
#do nothing
}
}
if($continue != 0 && $gibberish != 1) {
print OUTFILE"$key\n";
} else {
print OUTFILE"\n";
}
}
undef#handles; #closes all files
close(OUTFILE);
print "Process Complete! The output file is located in the current directory with the filename: _combined.out\n";
How do I check if a directory exists in lua, preferably without using the LuaFileSystem module if possible?
Trying to do something like this python line:
os.path.isdir(path)
This is a way that works on both Unix and Windows, without any external dependencies:
--- Check if a file or directory exists in this path
function exists(file)
local ok, err, code = os.rename(file, file)
if not ok then
if code == 13 then
-- Permission denied, but it exists
return true
end
end
return ok, err
end
--- Check if a directory exists in this path
function isdir(path)
-- "/" works on both Unix and Windows
return exists(path.."/")
end
The problem is that the stock Lua distribution (nearly) only includes features that are specified in standard C. Standard C makes no presumptions about there actually being a file system of any specific sort out there (or even an operating system, for that matter), so the os and io modules don't provide access information not available from the standard C library.
If you were attempting to code in pure standard C, you would have the same issue.
There is a chance that you can learn whether the folder exists implicitly from an attempt to use it. If you expect it to exist and be writable to you, then create a temporary file there and if the that succeeds, the folder exists. If it fails, you might not be able to distinguish a non-existent folder from insufficient permissions, of course.
By far the lightest-weight answer to getting a specific answer would be a thin binding to just those OS-specific function calls that provide the information you need. If you can accept the lua alien module, then you can like do the binding in otherwise pure Lua.
Simpler, but slightly heavier, is to accept Lua File System. It provides a portable module that supports most things one might want to learn about files and the file system.
If you're specifically interested in avoiding the LFS library, the Lua Posix library has an interface to stat().
require 'posix'
function isdir(fn)
return (posix.stat(fn, "type") == 'directory')
end
Well, the 5.1 reference manual doesn't have anything in the os table, but if you use Nixstaller, you get os.fileexists for precisely what you've explained.
If you can afford to fiddle around a bit, or if you know what OS you'll be running on, you might get away with the standard os library's os.execute with some system call that will identify if the file exists.
Even better than os.execute might be os.rename:
os.rename(oldname, newname)
Renames file named oldname to newname.
If this function fails, it returns
nil, plus a string describing the
error.
You could try setting oldname and newname the same -- you might not have write permissions, though, so it might fail because you can't write, even though you can read. In that event, you'd have to parse the returned error string and deduce whether you could write, or you'd have to just try executing your function that needs an existing file, and wrap it in a pcall.
You can also use the 'paths' package. Here's the link to the package
Then in Lua do:
require 'paths'
if paths.dirp('your_desired_directory') then
print 'it exists'
else
print 'it does not exist'
end
This is tested for the windows platform. It is quite easy actually:
local function directory_exists( sPath )
if type( sPath ) ~= "string" then return false end
local response = os.execute( "cd " .. sPath )
if response == 0 then
return true
end
return false
end
Obviously, this may not work on other OS's. But for windows users, this can be a solution :)
here is a simple way to check if a folder exists WITHOUT ANY EXTERNAL LIBRARY DEPENDENCIES :)
function directory_exists(path)
local f = io.popen("cd " .. path)
local ff = f:read("*all")
if (ff:find("ItemNotFoundException")) then
return false
else
return true
end
end
print(directory_exists("C:\\Users"))
print(directory_exists("C:\\ThisFolder\\IsNotHere"))
If you copy and paste the above into Lua you should see
false
true
good luck :)
I use these (but i actually check for the error):
require("lfs")
-- no function checks for errors.
-- you should check for them
function isFile(name)
if type(name)~="string" then return false end
if not isDir(name) then
return os.rename(name,name) and true or false
-- note that the short evaluation is to
-- return false instead of a possible nil
end
return false
end
function isFileOrDir(name)
if type(name)~="string" then return false end
return os.rename(name, name) and true or false
end
function isDir(name)
if type(name)~="string" then return false end
local cd = lfs.currentdir()
local is = lfs.chdir(name) and true or false
lfs.chdir(cd)
return is
end
os.rename(name1, name2) will rename name1 to name2. Use the same name and nothing should change (except there is a badass error). If everything worked out good it returns true, else it returns nil and the errormessage. You said you dont want to use lfs. If you dont you cant differentiate between files and directorys without trying to open the file (which is a bit slow but ok).
So without LuaFileSystem
-- no require("lfs")
function exists(name)
if type(name)~="string" then return false end
return os.rename(name,name) and true or false
end
function isFile(name)
if type(name)~="string" then return false end
if not exists(name) then return false end
local f = io.open(name)
if f then
f:close()
return true
end
return false
end
function isDir(name)
return (exists(name) and not isFile(name))
end
It looks shorter, but takes longer...
Also open a file is a it risky, because of that you should use lfs.
If you don't care about performance (and errorhandling -.-) you can just use it.
Have fun coding!
My preferred way of doing this in linux is
if os.execute '[ -e "/home" ]' then
io.write "it exists"
if os.execute '[ -d "/home" ]' then
io.write " and is a directory"
end
io.write "\n"
end
or, to put this into a function:
function is_dir(path)
return os.execute(('[ -d "%s" ]'):format(path))
end -- note that this implementation will return some more values
This feels so simple that I feel like there's a reason nobody else has done this.
But it works on my machine (Ubuntu focal), for files and directories.
It does however say that existent-yet-forbidden files don't exist.
For quick scripts and/or few files:
function exists(path)
return (io.open(path,"r") ~= nil)
end
Good practice:
function exists(path)
local file = io.open(path,"r")
if (file ~= nil) then
io.close(file)
return true
else
return false
end
end
For Linux users:
function dir_exists( path )
if type( path ) ~= 'string' then
error('input error')
return false
end
local response = os.execute( 'cd ' .. path )
if response == nil then
return false
end
return response
end
local function directory_exist(dir_path)
local f = io.popen('[ -d "' .. dir_path .. '" ] && echo -n y')
local result = f:read(1)
f:close()
return result == "y"
end
try this
nixio.fs
a package widely used in openwrt,
has lots of useful functions, and easy to use
docs:
http://openwrt.github.io/luci/api/modules/nixio.fs.html#nixio.fs.stat
fs.stat, lstat
> fs = require'nixio.fs'
> st = fs.stat('/tmp')
> = st.type=='dir'
true
> = fs.lstat'/var'.type=='lnk'
true
> = fs.stat'/bin/sh'.type=='reg'
true
tests:
> = pj(fs.stat'/var')
{
"dev": 17,
"type": "dir",
"modedec": 755,
"rdev": 0,
"nlink": 28,
"atime": 1617348683,
"blocks": 0,
"modestr": "rwxr-xr-x",
"ino": 1136,
"mtime": 1666474113,
"gid": 0,
"blksize": 4096,
"ctime": 1666474113,
"uid": 0,
"size": 1960
}
> = pj(fs.lstat'/var')
{
"dev": 19,
"type": "lnk",
"modedec": 777,
"rdev": 0,
"nlink": 1,
"atime": 1613402557,
"blocks": 0,
"modestr": "rwxrwxrwx",
"ino": 1003,
"mtime": 1613402557,
"gid": 0,
"blksize": 1024,
"ctime": 1613402557,
"uid": 0,
"size": 3
}
about stat(), lstat() syscall
shell test operator
[ -e path ]
[ -f path ]
[ -d path ]
[ -L path ]
low level both rely on this syscall.
$ strace test -e /var |& grep stat | tail -1
stat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
$ strace test -f /var |& grep stat | tail -1
stat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
$ strace test -d /var |& grep stat | tail -1
stat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
$ strace test -L /var |& grep stat | tail -1
lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0