Posts tagged ‘Linux’

Roxen Application Launcher 1.2.1

Roxen Application Launcher 1.2.1

There’s a new release of Roxen Application Launcher (come again?) for Linux.

Although the previous release, using GTK3, came quite recently this release has some new things.

GSettings

I dumped the “keyfile” solution for the application settings in favour to GSettings. So the settings is no longer stored in a file in the application directory but rather in the system’s application settings backend. GSettings is part of GIO – the GNOME networking library – and since RAL depends on GIO no new dependency is needed. The upside is that I could put a file of source code in the bin! Plus, it’s fun learning new stuff!

Editors and content types

Previously I have kept an editor – name and command line – for every content type. Anders at Roxen thought it’d be better if editors and content types were separated. I’ve thought about that before but never bothered to do anything about it.

But now, along with GTK3, there’s a new (I think) AppInfo class and the new AppChooserButton and AppChooserDialog widgets so I thought it’d be cool to use those. So selecting an editor for a new content type is way more simple now, and it also looks nicer. Plus we get the icon for the editor in the content type list under the “Applications” tab ;)

Simple logging

I also implemented some simple logging which can be viewed under the new “Logging” tab. This will be worked upon and at the moment not very useful information is written to the log, but at least it’s a start.

Default icons

The icons in the notification popup – which only are three to the number – is now fetched from the user’s default icon theme. They we’re bundled before.

SOUP all the way

Previously I have used a little hack for saving downloaded files to disk. The problem was that the Vapi bindings for libsoup casted the data to a string which totally scrambled binary content like images and such. My solution was to write a simple C-function which took a SoupMessageBody struct as argument and then wrote that to diskt always keeping the uint8[] type of the content.

I bug reported this way back and it’s now fixed in Vala so I dumped my solution and am now using Vala all the way. Gone is one C and one Vapi file.

While at it I changed from using blocking functions in libsoup to the async ones. You never really noticed blocking calls was used before, but right is right. Right?

And that’s that for this time I think!

Roxen Application Launcher 1.2.1

Sources is available at the Roxen Application Launcher Github repository

GTK TreeViewColumn with icon and text

TreeViewColumn with icon and text

The other day I wanted to put both an icon and text in the same GTK+ TreeViewColumn, and I had absolutely no idea how to do that. So I Google’d and Google’d but had trouble finding any examples. I even downloaded the source code of the Gnome System Monitor – where exactly what I wanted exist – but that was mostly written in C++ which I know very little of.

But I’m stubborn, and after a while I found and example in Python which I managed to interpret. Even though I know very little Python it’s not that hard to follow, and the example was short.

In short what’s needed is packing two CellRenderers in the same TreeViewColumn. Quite logical when you know about it. The example below is in Vala:

15 lines of Vala
  1. var tree_view = new TreeView ();
  2. var col = new TreeViewColumn ();
  3. col.title = title;
  4. col.resizable = true;
  5. var crp = new CellRendererPixbuf ();
  6. col.pack_start (crp, false);
  7. col.add_attribute (crp, "pixbuf", 0);
  8. var crt = new CellRendererText ();
  9. col.pack_start (crt, false);
  10. col.add_attribute (crt, "text", 1);
  11. tree_view.insert_column (col, -1);

I hacked up a simple application that shows all installed programs – that has a .desktop entry I guess – in a list (the screenshot above). The sources is available at my Github repository.

Happy coding!

Roxen Application Launcher 1.1

This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.

Screenshot of Roxen Application Launcher

There’s a new release of Roxen Application Launcher (come again?) for Linux.

I have updated the application launcher to use GTK3 so that it builds on Ubuntu 11.10 and any other Linux distribution using GTK3. This also made it possible to drop the dependency for libunique since Gtk.Application can handle single instance applications.

I also fixed a bug which made it impossible to use the appliction launcher on sites not running on port 80 or 443.

So there’s no new features in this release.

Roxen Application Launcher 1.1

Sources is available at the Roxen Application Launcher Github repository

Roxen Application Launcher 1.0.10

This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.

There’s a new release of Roxen Application Launcher (come again?) for Linux.

No big news, but the GTK+ tree view of files is now sortable. The “minimize to tray” function is now actually invoked when the window is minimized rather than closed. A right click in the file list now also let you go the the file’s directory in the Sitebuilder.

Also fixed a bug where the locales didn’t get installed correctly and also fixed a bug which scrambled the configuration file a bit.

Roxen Application Launcher 1.0.10

Sources is available at the Roxen Application Launcher Github repository

Notification area icons in Ubuntu 11.04

If you’r an Ubuntu user and have upgraded to 11.04 and use the new desktop environment Unity, you might have noticed that some applications that implement the GTK status icon doesn’t show up in the notification area – or tray or systray as it also may be called.

The reason for this is that Ubuntu now utilise a “whitelist” for which applications can be displayed in the notification area. You can (maybe not that) easily add any application to the whitelist by invoking the command gsettings in the following way:

1 lines of Bash
  1. gsettings set com.canonical.Unity.Panel systray-whitelist ['app-1', 'app-2', 'app-3']

Now, this can be quite a difficult command to remember and since you will need to first grab the whitelist, alter it, and then put it back. Since I’m lame at Bash I thought it would be a nice misson to create a Bash script that makes this interference simpler, just to pick up some more Bash knowledge. So I did!

The script can be used like this:

8 lines of Bash
  1. # Add MyApplication to whitelist
  2. systray-whitelist add MyApplication
  3. # Remove MyApplication from whitelist
  4. systray-whitelist remove MyApplication
  5. # Show applications in whitelist
  6. systray-whitelist show

And that’s that.

Download systray-whitelist 00:05, Wed 04 May 2011 :: 2.5 kB

Roxen Application Launcher 1.0

This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.

Screenshot of Roxen Application Launcher with context menu

So I had a go at the Roxen Application Launcher (come again?) for Linux. I added a context menu – when you right click – to the file list. When you right click a file in the list you get the option to view that file in the Sitebuilder, edit it or remove it.

Other than that there’s nothing new. And since the application seems to be very stable I decided to bump the version number to 1.0.

The sources is available at Github.

Roxen Appliction Launcher 1.0 00:06, Sun 12 September 2010 :: 376.2 kB

Roxen Application Launcher 0.4.4

This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.

So, here’s a new release of the Roxen Application Launcher for Linux (RAL). The previous versions used my home made (sloppy so) HTTP client which didn’t handle redirects or secure connections – thank you tec for the feed back – since I had some major problems getting libsoup working with binary files like images and such. Binary files was heavily scrambled when read from or written to disk so I made my own simple HTTP client that kept the data as a byte array to prevent some underlying libraries (GLib) from fiddling with it.

But I solved the libsoup issue so now the RAL handles redirects and secure connections. This is how I solved it:

The libsoup issue

When uploading a file back to the Roxen server I use IOChannel (g_io_channel in plain C) instead of Gio. So the upload works like this:

13 lines of Vala
  1. var sess = new Soup.SessionSync();
  2. var mess = new Soup.Message("PUT", get_uri());
  3. mess.request_headers.append("Cookie", get_cookie());
  4. mess.request_headers.append("Translate", "f");
  5. IOChannel ch = new IOChannel.file(local_file, "r");
  6. ch.set_encoding(null); // Enables reading of binary data
  7. string data;
  8. size_t len;
  9. ch.read_to_end(out data, out len);
  10. mess.request_body.append(Soup.MemoryUse.COPY, data, len);
  11. sess.send_message(mess);

And that seems to work like a charm!

When downloading data it’s a bit more tricky! Of course I tried using IOChannel in this case also but that made no difference. Downloaded images ended up 4 bytes long! But then I thought: You can make your own C bindings in Vala (remember the Vala compiler generates C code) through what is called Vapi files. So what I did was writing a C function that takes a SoupMessageBody object/struct passed from Vala and writes the data part to a file given as argument.

19 lines of C/C++
  1. gboolean save_soup_data(SoupMessageBody *data, const char *file)
  2. {
  3. FILE *fh;
  4. if ((fh = fopen(file, "w")) == NULL) {
  5. fprintf(stderr, "Unable to open file \"%s\" for writing!\n", file);
  6. return FALSE;
  7. }
  8. int wrote = fwrite(data->data, 1, data->length, fh);
  9. if (wrote != (int)data->length) {
  10. fprintf(stderr, "wrote (%d) != data->length (%d). Data may have been "
  11. "truncated", wrote, (int)data->length);
  12. }
  13. fclose(fh);
  14. return TRUE;
  15. }

And this was then made available to Vala by the following Vapi file:

6 lines of Vala
  1. [CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "")]
  2. namespace Soppa // Soppa is Swedish for Soup ;)
  3. {
  4. [CCode (cname = "save_soup_data")]
  5. public bool save_soup_data(Soup.MessageBody data, string file);
  6. }

And this is how the actual Vala code downloading the files looks like:

15 lines of Vala
  1. var sess = new Soup.SessionSync();
  2. var mess = new Soup.Message("GET", get_uri());
  3. mess.request_headers.append("Cookie", get_cookie());
  4. mess.request_headers.append("Translate", "f");
  5. sess.send_message(mess);
  6. if (mess.status_code == Soup.KnownStatusCode.OK) {
  7. // Here I call the C function made available through the Vapi file
  8. if (Soppa.save_soup_data(mess.response_body, local_file)) {
  9. message("The file was downloaded and written to disk OK");
  10. }
  11. else {
  12. message("Failed writing data to disk!");
  13. }
  14. }

So that’s that on that! ;)

The notification

I also – just for fun – implemented a notification mechanism through libnotify. Since I believe that can be rather annoying it’s not activated by default but can easily be activated by a checkbox in the user interface.

The packages

The Roxen Application Launcher for Linux can be downloaded at the download page at Github where also the work in progress sources is available or downloaded below!

Roxen Application Launcher 0.4.4 23:06, Wed 13 January 2010 :: 373.5 kB

Stay black!

Bitlyfier – A Bit.ly client for GNOME

Bitlyfier For those of us tweeting – or sharing web addresses in general – these long addresses with extensive query strings you wan’t to share isn’t too user friendly. So we have Bit.ly, among others, that lets you shorten a URL – or give it an alias if you like – and also gives you statistics on how many clicks it has and if it’s shared on Twitter and what not.

Since I’m on the quest of learning the programming language Vala I though why not making a Bit.ly desktop client for GNOME. So I did!

The desktop client

There’s really nothing extraordinary about it, in fact it’s quite simple. Put a long URL in the input field and hit “OK”. You’ll get the shortened URL back in the same input field.

NOTE! The screenshots is showing the Swedish translation but the interface is orginally in English.

Shortening a long URL
Shortening an URL with Bitlyfier

The shortened URL
The Bit.ly shortened URL

To use the application you will of course need a Bit.ly account. The first time Bitlyfier is launched it will ask for your Bit.ly account settings. Just fill in your username and API key (it’s found on your account page at http://bit.ly/account).

Bitlyfier account settings
The bitlyfier settings dialog

The command line interface

For the hacker you, Bitlyfier can also be used as a command line tool. These are the options:

11 lines of Plain text
  1. Usage:
  2. bitlyfier [OPTION...] - Bitlyfier, URL shortener/expander
  3. Help Options:
  4. -h, --help Show help options
  5. Application Options:
  6. -e, --expand Expands the given URL
  7. -s, --shorten Shortens the given URL
  8. -n, --no-gui Sets the application in command line mode
  9. -g, --gconf Invokes setting username and apikey

NOTE! You should quote the value of the ‘-s’ flag. If the URL to be shortened
contains a querystring with ampersands the URL will be truncated if it’s not
quoted.

So to shorten a long URL do like:

  user@machine:~$ bitlyfier -n -s "http://domain.com/long/url/to/shorten"

The Vala Bitly API classes

The Bitly API class I’ve written can of course be used standalone (it’s located in src/bitly.vala in the sources package downloadable below). Here’s an example of usage:

14 lines of Vala
  1. // main.vala
  2. // Compile: valac --pkg gee-1.0 --pkg json-glib-1.0 --pkg libsoup-2.4 -o main
  3. int main(string[] argv)
  4. {
  5. Bitly.Api api = new Bitly.Api("username", "R_the_api_key");
  6. Bitly.Response response = api.shorten("http://domain.com/the/long/url");
  7. stdout.printf("Short URL: %s\n", response.get_string("shortUrl"));
  8. response = api.stats("A2ma2z");
  9. stdout.printf("Clicks: %d\n", response.get_integer("clicks"));
  10. return 0;
  11. }

More about the Bit.ly API and what the API methods do can be read about at http://bit.ly/6HIqjS.

The sources

The development sources of this application is available at Bitlyfier at Github. The current stable release can be found at the Download page.

Gnome Font Manager

One thing I miss on Linux Gnome is font manager. Not just a font viewer but a proper manager like the old Adobe Type Manager. So I thought: Well, lets create one then! It might be that it already exist some font managers for Linux/Gnome but as always; this will be a good project for learning new stuff so I really don’t care if there are 1000 font managers out there ;)

Font parsing

The first thing to do, and that I have done, is porting my font parser from PLib to C#. That was no major head ache. There are at least to different font classes available in C# Mono (`System.Drawing.Font` and `Pango.Font`) but they don’t give all information about the font that I want.

Worth mentioning is that I heavily used the Mono DataConverter class to unpack the binary strings in the fonts. The unpack() function in PHP is just tremendous and there doesn’t seem to be a native alike in C#. But thanks to Miguel de Icasa’s DataConverter it went quite alright.

Font preview

The next thing to do was figuring out how to create the font previews. And I figured it out ;) First I though of using the console program gnome-thumbnail-font to create the previews but I had to throw that one into the bin since it doesn’t seem to handle multi line text. Since I’ve never used the graphics functions in C# before I came to the conclusion that I had to create the previews all by my self. It was quite easy finding good examples on the net of how to create text images with C#. A couple of hours later that problem was also solved (as you can see in the screen shot below). And man the graphics stuff in C# is fast. The preview images are generated instantly!

Next step

I have a lot left to do before this is a useful program but we’re heading there. One feature I’m planning on implementing is the ability to create your own font sets that you can activate/deactivate.

And I will probably come up with some more stuff to add, but that will be a later head ache!

Screen shot: Gnome Font Manager
Gnome Font Manager

Roxen Application Launcher for Linux

I thought I should broaden my C# knowledge a bit and you know how it is: To learn new stuff you need a real project to work on or else you will lose the fire sooner than later. So I came up with a good project that is actually useful to me: Porting Roxen’s “Application Launcher” to C#. There’s nothing wrong with the original one, written in Pike, except that it uses GTK 1 which is quite hideous (in an aesthetic meaning) compared to the newer GTK 2. And I also though it would be cool to create a panel applet (in the notification area of Gnome so you could put the Application Launcher in the background).

BTW: For those of you not knowing what the heck Roxen’s Application Launcher (AL here after) is here’s a brief explanation: Files in Roxen CMS is stored in a CVS file system which means that you don’t deal with files the way you normally do. To manage files you use a web browser interface (which is a darn good one I might add) but sometimes you actually want to edit files in your standard desktop application. And it is here the AL comes to play. You can download a file through the browser interface so that the file is opened in the AL. AL will then open the file in the desktop application you have associated with the file’s content-type. When you make your changes and saves them the AL will directly upload the changes to the server. So in short I could have said: The Application Launcher is a means to edit files on a remote Roxen server with a preferred desktop application.

The obstacles

I must say I’ve learned a lot from this project!

First off: If you download a file for editing and the AL is already started you don’t want to start a new instance of AL (this is something I have never ever thought about before – in general terms, not just concerning AL) but when you do think about it you find that it’s not a piece of cake to solve. I solved it the way it is solved in the original AL. The first instance of AL that is started also starts a “socket server” that listens for incoming traffic on a given port on the local IP. When a new instance is started it first checks if it can connect to said port and if it can it sends the arguments through the socket to the first instance which then handles the request. The second instance is simply terminated when it has send the data though the socket.

So there I had to do some socket programming. Great fun :)

Secondly: Stuff happens in the background of AL – data send through the socket remember – which means that nothing happens when you try to update the Graphical User Interface. (NOTE! This is the first more advanced desktop application I’ve done.) After “Google-ing” around a bit I came to know that this was a real newbie problem ;) The thing is that the GUI can only be updated through the same thread that started it so when using background threads – implicitly that’s what I’m doing although handled by the asynchronous callback infrastructure of C# – you need to make sure the GUI is updated through the main thread. This is the most simple way so solve it:

3 lines of C#
  1. Gtk.Application.Invoke(delegate{
  2. CallFunctionToUpdateGUI();
  3. });

That’s not too difficult when you know it ;)

Thirdly: The AL is sending data back and forth through the HTTP protocol which means we have to use some sort of HTTP client. C# has a couple of ways to do this but unfortunately they came up short, or I couldn’t use them anyway. I didn’t manage to figure out exactly why I always caught an exception saying something like: A protocol violation occurred!. I’m far from the only one who have fought with this and it has something to do with the headers sent from the remote server. You can invoke “unsafe header parsing” but that was to much of a hassle so I created my own little HTTP client.

One big annoying thing with C# is that is seems almost impossible to turn data from streams into strings without having to use any one of the System.Text.Encoding.* classes/objects which in my case meant that images and files in binary form got seriously fucked up. I manged to solve this my never turning the data into a string but keeping it as a System.Text.Encoding.* all the way from request to response to saving to disk. It was rather irritating but at the same time nice when solved (and I learned a whole bunch about System.Text.Encoding.*, System.Text.Encoding.*, System.Text.Encoding.* and System.Text.Encoding.*.)

Finally: Of course I learned a great deal more about C# but this blog post is starting to get pretty excessive so I will round it off by saying that MonoDevelop is starting to become pretty darn good! I just upgraded to the latest version of Ubuntu and that also meant that I got the latest MonoDevelop and I must say it’s more stable than ever (although it occasionally crashes) and a whole bunch of new features are in place. One I havn’t used before – although it might have existed before – is the “Deployment” stuff. It creates a package with configure and make files for optimal compilation. Really smooth!

Source and screens

I will finish off by adding the source files and a few screen shots:

Roxen Application Launcher 17:31, Sat 17 October 2009 :: 96.7 kB

Screen shot 1: Just a standard view
Roxen Application Launcher 1

Screen shot 2: The panel applet in action
Roxen Application Launcher 2

Screen shot 3: The Application Launcher in Swedish
Roxen Application Launcher 3

Screen shot 4: Adding support for a new content type
Roxen Application Launcher 4

International Womens Day

Logo: International Womens DayI thought I should honor the fact that today is the International Women’s Day. I think this is a day when we all should take the time to think about how the equality between men and women is holding up. It’s a fact that men has advantages in society at large; higher salary for equal work, more higher placed posts in powerful positions (take a look at Worldwide Guide To Women In Leadership) – more power for short – and the list can be made long. To honor this day I will below make a tribute to women I admire! And the order in which they appear i purely random.

Susanna Kallur

Susanna KallurSusanna – or Sanna as she’s called in Sweden – is currently the worlds fastest short hurdle runner and holds the 60 meters hurdle indoor world record – 7,68 seconds. I’m probably not the only guy (or woman) who like her since she’s probably the most beloved athlete in Sweden. What I like about Sanna is that she seems to be so incredibly secure in her self, extremely humble and very witty. It’s always great fun hearing her being interviewed after a race. So besides the fact that I find her to be very beautiful I admire her for the fact that she’s one of the most shining track and field stars in the world and still being so down-to-earth, but still you wouldn’t mess with her!

And by coincident she’s running in the World Indoor Championships this very day! Go Sanna

The image of Sanna Kallur is stolen from Aftonbladet.se and I am shameful!

Women in computing

Logo: LinuxChixIt’s no secret that women are under-represented in the world of web and software development! The reason for this I believe is purely an environmental/socializational thing. The same phenomenon can be seen in a wide range of areas and goes both ways for men and women. We are as children being taught what to wear, what to play with, how to speak and behave and so on, and the difference in how parents treat their sons and daughters is vast. It is, or at least it has been, a social standard that girls don’t get encouraged “playing” with computers which means they don’t grow any interest in using a computer in any other way than just using it! I’m will not bother ranting about this since there’s a ton of sociological studies addressing this problem – and I don’t mean the specific computer thing ;)

One thing that we male web and software developers can do to make it easier for women to participate in the world of software development is stop being so freaking sexist and boyish on email-lists and web forums. Sometimes you get worried when you see the tone in which some of the discussions is conducted on web forums for developers and I can really see why women get scared away. On one forum I participate in a girl asked a question – it was her first post on the forum – and the first reply she got was something in line with: Oh, you are a girl! Are you good looking?. No wonder I never saw her signature there again! I think we have a “Moment 22″ here: Since there’s almost only guys on these places it’s easy the tone gets boyish and that scares women away. So I think we guys need to think carefully about how we express our selfs on public email lists and web forums.

This is something that has been addressed by women and there seems to be a few organizations for “women in computing” that strives to make a change in, among other things, this area. Some organizations that deserves attentions is LinuxChix, Debian Women and GenderIT and I’m certain there are more than those two.

And here’s something to dig into: HOWTO Encourage Women in Linux, which I think also addresses women in computing in general.

Go ladies!

Women in my life

A day as this I must of course acknowledge the women that means the most to me, namely my Mom, my two sisters and my three sisters daughters. I love you all and I highly admire my sisters for their strength of personality, for what they have become and for how good mothers they are and for their beautiful families.

Now I just have to meet girlfriend!

A tribute to the International Womens Day

Firefox 3, Thunderbolted lightning…

What have they done to Firefox 3? I have a 64 bit system and still there are some things that doesn’t run on 64 bits, Adobe® Flash Player® being one of them. Another, more important, thing that doesn’t run when launched from a 64 bit browser is my Citrix® VPN client which I use when logging on at work from home. Anywho! There’s a browser called Swiftfox which is an optimized build of Mozilla Firefox® for Linux. The good thing is that Swiftfox runs in 32 bit mode so the Flash Player works and my Citrix client starts.

So what am I talking about! I noticed when I started using Swiftfox – which is built on a Firefox 3 beta release – that it’s insanely faster than Firefox 2. And I really mean insanely faster. Of course, as I said before, Swiftfox is an “optimized build of Mozilla Firefox for Linux” but I have used Swiftfox built on Firefox 2 before and that one wasn’t close to as fast as this last one is.

I think the Firefox team must have done some wonders to the rendering engine. I must admit that Firefox always has been a bit slower on Linux than on Windows and Mac so I pleased that Firefox 3 seems to be fastest browser ever known to mankind ;)

Script for adding all new files in a SVN repository

When working with revision controlled stuff you sometimes add loads of new files to an already existing repository. Then when you are about to check in the next revision you have forgotten where all the new files are and you probably don’t feel like writing svn add thefile too many times. This is of course no problem if you’r using a decent SVN client – like Tortoise SVN on Windows – but I prefer the command line so the solution was writing a script that adds all new files in a directory structure to the SVN repository.

There are “one liners” for this but I wanted a bit more flexibility and ease of use so I wrote the a script that also lets you define regexp patterns for files you don’t want to add even if they exist in the directory structure.

This is how to use it:

7 lines of Bash
  1. # Add all new files
  2. svnadd path/to/repository/
  3. # Add all new files except those matching the regexp
  4. svnadd -s ".*.txt|tmp/.*" path/to/repository/
  5. # Add all new files except those matching the regexp in
  6. # the file defined by the "-f" flag
  7. svnadd -f regexp.txt path/to/repository/

Quite easy! If you don’t feel like remembering the pattern for files to skip, put the regexp in a file and use the svn add thefile flag.

77 lines of Bash
  1. #!/bin/bash
  2. ##########################################################################
  3. #
  4. # Script for adding all new files in a directory structure to an SVN
  5. # repository.
  6. #
  7. # copyright © 2007 Pontus Östlund <spam@poppa.se>
  8. #
  9. # The svnadd script is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or (at your
  12. # option) any later version.
  13. #
  14. # The svnadd script is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  17. # Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software Foundation,
  21. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. ##########################################################################
  24. while getopts "s:f:h" opts
  25. do
  26. case $opts in
  27. s) skip="$OPTARG";;
  28. f) if [ -f "$OPTARG" ]; then
  29. skip=$(head -n 1 $OPTARG)
  30. else
  31. echo "$OPTARG doesn't exist!"
  32. fi
  33. ;;
  34. h) help=1;;
  35. esac
  36. done
  37. shift $(($OPTIND - 1))
  38. if [ -z $1 ] || [ "$help" ]; then
  39. echo "About: svnadd enables you to add all new files in [dir] to a "
  40. "subversion repository"
  41. echo "Usage: svnadd [flags] [dir]"
  42. echo
  43. echo " -s <pattern> Regexp pattern for files to skip"
  44. echo " -f <path> Path to file containing regexp for files to skip"
  45. echo " The regexp should be placed in line one!"
  46. echo " [dir] The path to the repository"
  47. echo
  48. echo "Example: svnadd svnsrc/"
  49. echo "Example: svnadd -s 'tmp/.*.xml' svnsrc/"
  50. echo "Example: svnadd -f regexp.txt svnsrc/"
  51. echo
  52. exit 0
  53. fi
  54. dir=$1
  55. if [ ! -d "$dir" ]; then
  56. echo "$dir is not a directory"
  57. exit 1
  58. fi
  59. while read status file; do
  60. if [ "$status" = "?" ]; then
  61. res=$( echo "$file" | egrep -o "$skip" )
  62. if [ -z "$res" ]; then
  63. svn add "$file"
  64. fi
  65. fi
  66. done<<EOF
  67. $( svn st "$dir" )
  68. EOF
  69. exit 0

Download

svnadd 17:31, Sat 17 October 2009 :: 2.1 kB