momijizukamori: Grey tabby cat with paws on keyboard and mouse. The text reads 'code cat is on the job', lolcats-style (CODE CAT)
[personal profile] momijizukamori
So we've required files to be tidied using perltidy since 2019, buuuuut I am terrible at remembering to manually do it, so! I threw together a quick'n'dirty way of automatically running tidy on commit. It's based on this example from the Prettier docs (Prettier is like perltidy but for CSS/JS/HTML).

Here's the perl variant of the script:
#!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0

# Prettify all selected files
echo "$FILES" | xargs tidyall

# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add

exit 0


This also has the bonus that it only tidies files you added to your commit, so you don't end up with rogue changes in files you didn't touch because someone else forgot to tidy before a branch got merged!

EDIT: [personal profile] kareila rightfully pointed out that I didn't actually specify the install instructions (they're in the linked Prettier docs but, uh, that's not that intuitive). This script should go in the file .git/hooks/pre-commit, and that file needs to be executable, which you can do on the commandline by running chmod +x .git/hooks/pre-commit
alexwlchan: (face)
[personal profile] alexwlchan
I was chatting to [personal profile] cesy this evening, and we were chatting about tagging on Dreamwidth (because I've just written about how I use tags to organise my scanned documents). In particular, we were talking about ways to find posts with particular combinations of tags.

As far as we both know (please correct us if we're wrong!), you can only filter your posts by a particular tag. For example, to see all of my posts tagged with "meta", I'd visit https://alexwlchan.dreamwidth.org/tag/meta.

What if you want to search by more than one tag? For example:
  • Which posts have I tagged with reviews and quotes? (An AND query)

  • Which posts have I tagged with at least one of person:alex or person:lexie? (An OR query)
I decided to try writing a script for this.

I already had code that uses the XML-RPC API to get all my posts (to get a backup of my Dreamwidth entries). I added some extra filtering, and now it can search posts using the queries of the form above.

Usage

  1. You need Python installed (downloads page). Python 2.7 or 3.x is fine; if you already have Python installed on your computer, that should be fine.

  2. Copy the code below into a file, for example search_dreamwidth_posts_by_tag.py.

  3. Run the script with Python, for example by typing python search_dreamwidth_posts_by_tag.py in a terminal.
The script will ask you for your Dreamwidth username and password (to talk to the API), and what sort of tags you want to search for. It saves the results to a spreadsheet, for maximum nerd points.

Reusing the code

If you know a bit of Python, you should be able to pull out bits of this code and reuse it elsewhere -- the XML-RPC API client, downloading all your posts, checking a user's password. You could modify it to find posts by different criteria: posts within a particular date range, or posted at the weekend, or that don't contain the letter e.

MIT license.

The code

Code behind a cut tag )
jeshyr: Programming dreamsheep (Dreamwidth - Development)
[personal profile] jeshyr
Just to let folks know, the ombibus jeshyr-do-anything script at http://dw-dev.dreamwidth.org/94822.html has been upgraded to cope with git.

It doesn't do quite as many things as it used to, but it does all the basics and I'll add new things back in as I figure out how to do them with git.

Jobs it currently handles include:
Apache server up/down/restart
Move between free/nonfree directory trees
Update databases
Upgrade your hack with github code
Hard reset your hack to current github state
Tidy old patching artefacts
Show apache error logs

It used to make patches and handle diffs and stuff but since that's all *so* different in git I just ripped it out and will re-add as appropriate.

You can always find the code at http://dw-dev.dreamwidth.org/94822.html - I won't include it here, trying to keep it just in one place or we'll end up with 27 different versions.

Comments, brickbats, boquets, requests, and suggestions welcome :)

Cheers,
r
vlion: (matrix)
[personal profile] vlion
Hi,

I have a Posterous->dw migration script. It kind of works. It worked for me taking my Posterous backup and putting it on a Dreamwidth install foxfirefey has going.

However, it is a funky stanky horrid mash of Python and Ruby. It code smells like old socks.

It does:

- give you dates

- Give you titles.

- Give you actual post.

It does not

- Do formatting.

- Do images.

- Do easy. It requires a few rubygems[1].


---

So. Is this going to be useful? Helpful? I can stuff it up on a github and maybe someone can take this and turn it into mo' usable code. What needs to happen - IMO- for mo' happiness is:

- Username/password not on the CLI, instead, an interactive dialog

- Ruby removed and replaced with Python such that the Python default install works.

- Formatting handled appropriately. Python Etree explodes on posterous html; HTMLParser is underpowered and will require gyrations to do this right.


Let me know what people want, if this is something wanted, I'll upload it.



[1]. If you're not a developer on Linux/OSX, this is going to be (a) gibberishy and (b) impossible to deal with in any sort of way that doesn't involve grief.
mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
[staff profile] mark
If you use the "dwu" script from the wiki, you will need to update your local copy. I've made some changes because the last version of the script would merge changes from both develop and master, leading to broken environments and GitHub repositories.

http://wiki.dwscoalition.org/wiki/index.php/Dev_Maintenance#dwu_-_Updating_the_repos

Please use the updated script.

If you have gotten yourself into a broken state, let me know and I can walk you through fixing it. There is some force pushing involved, sadly.
momijizukamori: Green icon with white text - 'I do believe in phosphorylation! I do!' with a string of DNA basepairs on the bottom (Default)
[personal profile] momijizukamori
...mostly because as anyone who gets all the bugzilla and/or style notifs knows, I did a lot of that this week *g*

First, preview images - I'd been doing them with Ubuntu's screenshot utility and photoshop, which is 1) really slow and 2) doesn't really adequately strip and compress images. So! Enter Screen Capture for Google Chrome, which I've been using with the 'full page' setting, and set to skip pop-ups and save straight to a temp image directory, where I can then rename the screenshots. After that, [personal profile] geekosaur and [personal profile] exor674 (with a little sideline ImageMagick input from [profile] tamouse_ helped me write this handy little shell script, to process all the pngs in the directory you run them on - it resizes them, crops them, strips color profiles, and indexes them.



I've been using it on my own machine, as I run Ubuntu, but I believe all the appropriate packages are now on the Dreamhack server, too, for server-side use.

Second, [personal profile] rb posted a handy little script for sorting properties for color themes and generating appropriate headers. I updated it to match our current formatting for files, add sorting for a few more properties, and output more verbose instructions on what to do next at the end.



This is written to be used server-side right now, with a command-line input like './newtheme.pl "Human-Readable Theme Name" user "Layout This Theme Is For" yes < inputfile' I've been running it client-side by changing line 74, 'my $filename = "$ENV{LJHOME}/temp/$layout_name-$theme_name.s2";' to 'my $filename = "temp_themes/$layout_name-$theme_name.s2";' (otherwise it tries to write to root, and That's Bad. And unnecessary)

Third, for the tiny handful of people doing S2 work on gedit (shhh, I like it, okay), I made some mods to the CSS syntax highlighting file (pastebin because the file is big). I tried to get it to make a custom S2 language, but it was being fussy about parsing it, and a lot of the .s2 files are largely CSS anyway. So this adds highlighting for S2 variables and S2 keywords! It goes in a file called CSS.lang in home/.local/usr/share/gtksourceview-2.0/language-specs, which will probably not exist if you haven't made custom languages. If you're on newer versions that use GTK3, that 2.0 should be a 3.0. You may have to manually select the highlighting, for some reason it only registers the .s2 extension some of the time.
jeshyr: Dreamwidth: Dream wide, dream deep (Dreamwidth - Dream wide Dream Deep)
[personal profile] jeshyr
Right before my brain got refried by this stupid disease I was working on a script to turn the theme layers copied from DW itself into the right format to paste into the s2 code in the sourcecode. I was doing it as I learned how so it's only been tested on about 5 different situations at the moment and I'm quite sure it doesn't do everything so check all output please!!

And yes, my brain got fried (again) by this stupid disability so I'm on indefinite leave from developing for the mean time - and VERY disappointed about it.

At the moment you want to pipe the theme layer through STDIN to the script, so something like

$ ./newtheme.pl NewThemeName Rising "Tabula Rasa" yes < ~/file-with-theme-layer.txt

it will tell you what file it writes the output to, it will be something in $LJHOME/temp/

Script



Feedback, cases that break it, improvements, etc. would all be great.

r

Edit: Now with super bonus functioning HTML tags!
fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
[personal profile] fu
[personal profile] exor674 has added another tool to the dev tools repository, called lookup-routing

It does several things.

First, you can easily find out which file handles what page (e.g., /nav, /nav/create, /rename, /admin, /post, etc).

$ lookup-routing /admin
app: /admin is a redirect to /admin/
app: /admin/ is defined in the file cgi-bin/DW/Controller/Admin.pm, and using the handler sub admin_handler


This is useful if you're working on a bug that's been reported on /some/path/here, and you want to know which file to open up first.

(Psst If "lookup-routing /some/path" doesn't work, it is probably a BML file. Try htdocs/some/path.bml)


--verbose gives you a much more detailed view (plus some debugging tips) )


Second, you can get a list of everything in the routing table, using the --list argument:
$ lookup-routing --list

You can filter the list down to either those that use regex matching, or those that use string-matching:
$ lookup-routing --list --regex
$ lookup-routing --list --string


You can also filter down to just those pages in user-space, app-space, or ssl using --role=user, --role=app, --role=ssl, respectively. Default is --role=all.

There are --user, --app, --ssl shortcuts which do the same as their --role=... equivalents.

$ lookup-routing --list --user # lists paths handled by the routing system that follow the form http://exampleusername.dreamwidth.org/some/path/here
$ lookup-routing --list --app # lists paths handled by the routing system that follow the form http://www.dreamwidth.org/some/path/here
$ lookup-routing --list --ssl # lists paths routing system that use https


And third, you can get a quick summary of stats by running
lookup-routing --stats


A quick reminder of which arguments to use is available by running:
lookup-routing --help

Very detailed usage instructions can be found by running:
lookup-routing --help --verbose


If you haven't already installed the dev tools yet, see the Dev Tools wiki page. If you've installed the dev tools before, make sure to update your code, to pull in the changes.
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
[personal profile] sophie
I've just put a mass user-creation script on the wiki. It allows you to create any number of users and have them be auto-validated. It will also randomly create watch/trust edges between the created users, and if you specify it, they will all join any given community. This makes it extremely useful when you have a bug that requires a large number of users to test, such as bug 2215: member list page: "jump to account" does not jump to username, which requires more than 100 users in a single community.

(I actually already had this script created some time ago, but hadn't released it publicly. However, when I saw [personal profile] kjwcode manually creating 100 users in order to test the patch on the aforementioned bug, I added the community-joining ability and offered the script to him, and realised I should probably release it for all to use!)

There are a few things the script doesn't do yet. For example, while it can make all the users join a community, it won't make any of them subscribe to it. If anybody wants more features added, let me know!

And, in the interests of code preservation (in case the wiki ever disappears for some reason - not that it should), I'm reproducing the code as it is now inside a cut. Bear in mind that it's possible that the version on the wiki may be more up-to-date if it's been some time since this post was made, so you should probably check on the wiki first!

Source code follows! )
jeshyr: Pile of thick books labelled "Geek" (Geek)
[personal profile] jeshyr
[BTW: I am editing this post as the script is updated so refer back for further edits.]

I'm just a newbie at developing - submitted my first patch today - and one of the things one has to do to get up and running is to read about 5 tons of documentation and figure out workflows. Since I was having lots of potentially useful scripts suggested to me by developers and by the wiki and since I am at heart a toolmaker I put them all together and documented everything to the best of my ability.

I think this works but it's way past my bedtime right now and I haven't tested every single combination so if it eats your code, your data, or your firstborn child be in on your own head. OTOH I think it should work right!





For new folks, you need to copy everything in the text box above and paste it into a new file on your Dreamhack. I suggest you put it in the ~/bin directory and call the file 'dw', because then your system matches mine :). Then you need to make that file executable by typing 'chmod +755 ~/bin/dw' or whatever filename you used. After that you can type 'dw' and it should execute just fine, it'll give you instructions.



I would welcome fixes, constructive criticism, or anything else you have to offer. Feel free to use this in any way you want, etc.

r
pseudomonas: My rat is confused by technology (technology)
[personal profile] pseudomonas
Does LJ::Simple work reliably with Dreamwidth? If not, is there a comparable perl module that does? (I'd rather rely on someone else's testing than conduct my own, which is likely to be more slipshod)

Also (and relatedly), is there a way that given a DW entry that's been either imported from, or crossposted to, LJ, I can get (programmatically) the ID or URL of the LJ entry, without resorting to comparing timestamps and post contents?

ETA: if there's no Perl thing suitable, does anyone have any ideas for Java packages that would do the same?

(x-posted from [community profile] perl, where I got suggestions to try here)

ETA: http://www.chiark.greenend.org.uk/~adamb/dw-thataway.pl.txt is the current state of the script. I've tested it on a small test journal and it seems to do what it's supposed to do. If anyone's brave enough to test it on real-world data and let me have any bug reports, that'd be wonderful.

Profile

dw_dev: The word "develop" using the Swirly D logo.  (Default)
Dreamwidth Open Source Development

June 2025

S M T W T F S
1234567
89101112 1314
15161718192021
22232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 15th, 2025 06:29 am
Powered by Dreamwidth Studios