Trying to create a handler for .maff files in Linux - linux

MAFF files are simply zip files. I'm trying to create a handler for .maff in linux so that when I click on them or type xdg-open x.maff it will call my handler instead of the default which is to open the directory in nautilus. I created an application-x-maff.xml file that contains:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-maff">
<comment>maff type</comment>
<magic priority="100">
<match offset="0" type="string" value="PK\x03\x04" />
</magic>
<glob pattern="*.maff"/>
</mime-type>
</mime-info>
and saved in ~/.local/share/mime/packages. Created also a ~/.local/share/applications/maffapplication.desktop that contains
[Desktop Entry]
Type=Application
MimeType=application/x-maff
Name=Maff Handler
Exec=<my home path>/bin/linux/maffHandler
and executed
% update-mime-database ~/.local/share/mime/packages/
% update-desktop-database ~/.local/share/applications
If I do
% gio info x.maff (filtered)
standard::content-type: application/x-maff
standard::fast-content-type: application/x-maff
and if I do
% gio mime application/x-maff
Registered applications:
maffapplication.desktop
Recommended applications:
maffapplication.desktop
everything seems to be right ... but then xdg-open x.maff does not work, still calls nautilus ... worse yet, if I do
% xdg-mime query filetype x.maff
application/zip
I'm sure I'm missing something ... somehow I need to override this association between the .maff file that starts with the same magic as a zip file to no avail ... I tried all kinds of modifications on the xml file, with and without the magic, nothing works
By the way, if I do
% maffHandler x.maff
it works perfectly and opens the maff file in firefox, I'm willing to share the C++ code of that if anyone is interested

Seems that TDE (Trinity Desktop) does not properly set two important environment variables
setenv XDG_CURRENT_DESKTOP KDE
setenv KDE_SESSION_VERSION 5
Once they are set at .login (unfortunately had to log out and login again) xdg- scripts started working properly and recognizing the MIME types. The other problem is that TDE requires that you manually add the association on Control Center -> TDE Components -> File Associations.
After environment variables properly set for my environment and File Associations set, then it all works perfectly. Thanks

Related

Could not read log4j.properties

We are having a module which contains log4j.properties and other files in it. And there is a separate module which is dependent on the 1st module(Realign). So we had made the 1st module as a jar file and placed it in the WEB-INF/lib folder of the second module(Reasign). We are running the modules in Liberty server. But still we are getting the File Not found exception as below,
log4j:ERROR Could not read configuration file
[file:/metlife/runtime/installed/wlp/usr/servers/bobr/apps/expanded/bobr.ear/BOBReassignmentWeb.war/WEB-INF/lib/Realignment.jar!/r_resources/log4j.properties].
[9/12/18 8:28:51:591 EDT] 000002de SystemErr R java.io.FileNotFoundException:
file:/metlife/runtime/installed/wlp/usr/servers/bobr/apps/expanded/bobr.ear/BOBReassignmentWeb.war/WEB-INF/lib/Realignment.jar!/r_resources/log4j.properties (No such file or directory)
It looks like your PropertiesConfigurator class is taking a file path (as a String). If you used a URL instead, I think that would work - that way, you would get a JAR URL which includes the path to the JAR (or WAR, EAR, etc.) archive and the path inside the JAR. If you have control over the PropertiesConfigurator code, then I would recommend changing it so that it loads the file via URL.
If that is not an option, then you could extract the properties files and put them on the file system directly. For example, you could create a directory in your server directory (for an example, we'll call it log4jProps). Then you could create a shared library in your server config (server.xml) like this:
<library id="log4j.props">
<fileset dir="${server.config.dir}/log4jProps" includes="r_resources/*properties"/>
</library>
then update your application configuration to use this library as a common shared library:
<application id="myApp" name="myApp" location="myApp.war"...>
<classloader commonLibraryRef ="log4j.props" />
</application>
For good measure, you should probably remove the properties file from your application archives - that way they won't be loaded from there, and then throw off the PropertiesConfigurator like it is now.
Hope this helps,
Andy

Remote creation of Custom actions in Thunar

I'm using Thunar as file browser for a linux network composed of 100 CentOS 7.2 machines. We are managing the installation of those workstations with a PXE server and SaltStack installation.
I need to create those custom actions during the installation.
Currently, Thunar is installed on every workstations, the script is available on a share but I need to create the custom action on each machine. Open Thunar, Edit > Create custom actions and it launches my script in xterm for the selected folder:
xterm -e "/path/to/my/script.sh %f"
Is there a way to create Thunar's custom actions from command lines or by editing a file so that I will be able to launch them through Salt cmd.run?
Thanks for your help.
I've found out that those Custom actions are store in this file:
cat ~/.config/Thunar/uca.xml
Here is an example of the syntaxe:
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
<icon>script.png</icon>
<name>My custom action</name>
<unique-id>1479309009025049-2</unique-id>
<command>xterm -e "/path/to/my/script.sh %f"</command>
<patterns>*</patterns>
<startup-notify/>
<directories/>
<audio-files/>
<image-files/>
<other-files/>
<text-files/>
<video-files/>
</action>
</actions>
That way, I can create this template file and copy it in the user folder.

how to make tornado auto restart when certain files changes

I'm using Tornado working with Python 3 and Linux server, when I edit and save some text or XML files I want Tornado to restart itself. I checked the document and found the autoreload module and the watch function here.
It seems it only worked for pyo files. What can I do if I want it to reload when a certain URI is modified?
Setting the debug flag to True in settings forces Tornado to reload whenever a file is modified or whenever a URI is changed in app.py (or where ever you have defined your handlers). Tornado also automatically reloads template files so any changes in there will be seen instantly.
settings = {
'debug':True,
# other stuff
}
tornado.web.Application.__init__(self, handlers, **settings)
the file added must be an absolute path.
def addwatchfiles(*paths):
for p in paths:
autoreload.watch(os.path.abspath(p))
addwatchfiles('config.xml')
config.xml is at the same directory in where the server's python file start at.
You need to turn autoreload on:
tornado.autoreload.start()
tornado.autoreload.watch('myfile')
Complete example at https://gist.github.com/renaud/10356841

NLog can't write to the log file in the install directory

I have an application that logs, and I don't get any file-based logging when I deploy it to the default directory. It seems clear that the reason is that writing to "c:\program files (x86)\blah" requires elevated privelege levels which my app doesn't have. So I end up telling users "install to "c:\blah" and it will work fine, which it does. But that seems rubbish. Any alternative?
You could configure NLog to log to a different folder. NLog has SpecialFolderLayoutRenderer that allows you to use .NET's special folders. You should be able to specify the log file name using the SpecialFolderLayoutRenderer. Maybe something like this (I have not tried this):
<target name="file" xsi:type="File" layout="${longdate} | ${logger} | "${level} | ${message}" fileName="${specialfolder:folder=MyDocuments:dir=LogFiles:file=${shortdate}.log}" />
That should (if it works) create log files in a LogFiles subfolder in the user's Documents folder, with the actual log file names corresponding to the date. I don't know, but I would guess that NLog will create the LogFiles folder the first time anything is logged.
Good luck!
For me it worked like this:
fileName="${specialfolder:folder=ApplicationData}/newDMS ClientApplication/Logs/${shortdate}.log"

Mime types for custom file type

I'm trying to register a custom file type as a mime-type in linux. My custom filetype, with a custom extension, is actually a zip archive containing various xml and other files.
The problem I'm having is that my operating system (kubuntu) won't recognize the file as my custom mime-type but insists on it being a zip file.
I'm not sure where I should start trying to fix my problem. I've used the following mime info file (tugraz-caleydo.sharedmimeinfo):
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-cal">
<comment>Caleydo Project</comment>
<glob pattern="*.cal"/>
</mime-type>
</mime-info>
My Desktop Entry (caleydo.desktop, correctly registered in /usr/share/applications):
[Desktop Entry]
Version=2.01
Encoding=UTF-8
Name=Caleydo
GenericName=Data Visualization
Comment=Visualization for Molecular Biology
Exec=/usr/bin/caleydo
Icon=/usr/share/pixmaps/caleydo_256.png
StartupNotify=true
Type=Application
Categories=Science;
MimeType=application/x-cal;
And these are the commands I'm trying to use:
sudo xdg-mime install --mode system tugraz-caleydo.sharedmimeinfo
sudo xdg-mime default caleydo.desktop application/x-cal
sudo update-mime-database /usr/share/mime
However, this still gives me:
$ xdg-mime query filetype export_2012.cal
application/zip
I finally found the issue:
the mime info file has to have exactly the name of the mime type. Renaming it to x-cal.xml did the trick.

Resources