Categor铆as
c贸digo abierto Mundo 2.0 programaci贸n Tutoriales WordPress

Trabajando con SVN (y WordPress)

Esto es un reblog de trabajo para no perder el archivo. C贸mo usar SVN para tus traducciones de WordPress, en ingl茅s. Lo guardo por hist贸rico, porque en pr贸ximas versiones esta forma de trabajar dejar谩 de funcionar.


Using SVN in your translation flow聽is not as hard as it seems. If you know some of the basics, you can聽update a repository (for themes, plugins, or core) in an easy way. Let’s begin :).

We are going to work with the example of the Spanish (Spain) translation. What do we need to begin with?

Permissions

First of all, we need to have permissions granted to write to our Subversion repository. We can ask for聽this access in the make/polyglots site.

make-polyglots

Don’t forget to:

  • Ask for access politely
  • Indicate聽your wp.org user
  • Indicate聽the repository you want access to (you need to be a validator for your language to be granted commit access)
  • Tag your post with聽request. Locale tags are not needed, as they are automatically associated with validators, but they will be appreciated by others translators and validators.

Creating聽your own local copy

Now that you have access to the repository, you need to make聽your own local copy to work with it.

First, you need to locate your locale’s repository.聽You can look for it in聽https://i18n.svn.wordpress.org. Once you have located it, copy the URL. For the Spanish example, the URL is https://i18n.svn.wordpress.org/es_ES/

The next step is to make the copy. If you are a Mac or Linux user, you only need to go to a terminal. If you are a Windows, user, you can install Win32SVN to work with a terminal with SVN.

We are going to use SVN. SVN is an abbreviation for Subversion, a software versioning聽and revision聽control by Apache. SVN (and other revision control software, like git) allow the programmers to work in a collaborative way and allow to all the people involved to look at and review the code, modify it, and revert it if there is any problem.

Once you have your terminal ready, you need to write this with your own locale:

svn-co

Now you’ll see a lot of archives being copied, and you will have聽all your locale repository copied in your local directory.

archive

copied

SVN basics

Note that you are right now in a SVN repository. You can see what others have done in the repository by using the command svn log. When you submit your聽changes, others will see your activity in the logs.

SVN is a little wayward. When you are in a SVN repository, you need to remember to alway use the command svn to do things.

  • if you want to copy something, you need to use聽svn copy or聽svn cp
  • if you want to move something, you need to use聽svn move or聽svn mv
  • if you want to delete something, you need to use聽svn delete or聽svn del
  • if you add a new file to a directory and want it to be in the SVN repository, you need to use聽svn add <file> to add it to the next commit

You have a list of all the available commands writing svn help in your local repository.

blame

Creating a new tag and/or branch

Now that we have our local repository, we need to create our new branches and tags. We are going to work with the example of WP 4.0-alpha.

As we see before, when you create a new file or archive you need to add it to the repository. If you do not add it, you will not be able to commit your files to the repository.

To make things easier, we are going to svn copy a prior directory and modify the files.

First step, we go into the聽tagsdirectory. We will have a list of all prior tags.

Now, we copy the last directory created to a new one with our version:

svn-cp

Done! Now we can navigate with our browser to make things easier.

Understanding the repository

In our new directory we will see two directories:聽dist and聽messages.

The dist directory has this content:

  • license.txt – the license archive
  • licencia.txt – name may vary. This is the license in your language.
  • readme.html – the readme file in your language.
  • wp-admin/setup-config.php – a translated version of the setup in your language
  • wp-config-sample.php – a translated version of the config sample in your language

The messages directory has this content:

  • admin-xx_XX.mo – the translation archive for the administration ( link聽)
  • admin-xx_XX.po – .po version
  • admin-network-xx_XX.mo – the translation archive for the network administration ( link聽)
  • admin-network-xx_XX.po – .po version
  • continent-cities-xx_XX.mo – all the translated Continents and Cities to your language ( link )
  • continent-cities-xx_XX.po聽– .po version
  • xx_XX.mo – the main WordPress translation ( link )
  • xx_XX.po聽– .po version
  • twentyxxxxx – the translation of each official theme (various directories)
    • xx_XX.po
    • xx_XX.po

Updating your files

At this point, we need to update the files of our new directory to commit the new version. To do this, we need to know how are we going to build the new package.

packagesIf you聽are going to use the聽translate.wordpress.orgoption,

  • All the installation and setup archives will be read from our new /dist directory (and we will tell the system聽where they are)
  • The translations will be read from the translate.wordpress.org site

If you聽choose the Subversion option,

  • All the installation and setup archives will be read from our new /dist directory (and we will tell the system聽where they are)
  • All the translations will be read from our translations svn directory (and we will tell the system聽where they are)

You should聽always try to use the first version. If you need to use the second version, then you will need to:

  • go to each one of the translation sites in translate.wordpress.org (you have the links here)
  • export the translations in .po and .mo versions
  • change the names of the archives to match the list before
  • put them in聽the svn directory in their correct place

Regardless聽the option we want to use, we need to update the archives in the聽dist聽directory. Usually, you will only need to update the version number in the readme.html file. If you need to do something else, it will be mentioned聽in the聽make/polyglots聽site.

readme

After finishing with the archives and changes, we can use the command svn status聽in our parent directory to see the changes that are going to be committed.

svn-status

Committing changes

  • If we are committing a minor version (3.9.1 for example), we will need to commit a tag with the new version
  • If we are committing a聽major version (4.0 for example), we will copy this new tag to a branch to upload the tag and branch

svn-branch

If we are using the Subversion option we will see the list of all .po and .mo archives; it’s a good idea to update the .mo and .po archives in the /trunk directory as well.

If we are using the translate.wordpress.org option, we are ready to commit our changes.

The command to commit our changes is svn commit or svn ci. We will add a message using the -m subcommand, containing:

  • the version we are uploading
  • the language we are uploading
  • please use english to make understanding easier

svn-commitAnd done! We are ready to go to our local WordPress.org site and build the new version of WordPress.

Building a localized WordPress 聽version

If you have just committed the files to the repository, you will need to wait a bit to see it appear in your local WordPress.org site.

Once it’s working, you need to select:

  • the translate.wordpress.org聽option
  • the /dist/ directory
  • the development (trunk) project

The WordPress version will change and you will see the last version in development. The revision number will be ignored, it only works in the Subversion option.

version-2

If you want to build an official release version, you will need to look in the project list and select the one that you are looking. You will get the last minor version released. Again, the version will be automatic and the revision number will be ignored.

version-prior

You can build and distribute as many beta and release candidate versions as you want. They will automatically go to the beta and release candidates place.

rc-versions

Categor铆as
Mundo 2.0 programaci贸n Tutoriales

Entorno de desarrollo continuo con github y deployHQ

Una de las cosas que me est谩 tocando hacer en mi nueva empresa es el staging. Buscar formas para que podamos tener un desarrollo continuo de todos nuestros productos y servicios, a la vez que tengamos todo controlado perfectamente.

Uno podr铆a pensar que con github puede ser suficiente para montar un entorno como el descrito. Y lo es. Aunque soy m谩s fan de crear releases y desplegarlas, podemos utilizar los commits como puntos de anclaje y as铆 poder ir hacia adelante y hacia atr谩s en sus cambios.

Pero claro, a nosotros no nos importa entrar en el servidor y hacernos nuestro git push. Y no todo el mundo es como nosotros.

Adem谩s, cuesti贸n comprensible, mi jefe me pide poder hacer 茅l los commits de forma aut贸noma despu茅s de haberlos comprobado en el servidor de desarrollo. Y un m茅todo igual de sencillo para poder revertirlo. 驴Qu茅 soluci贸n le damos?

Git como herramienta de versionado

Est谩 claro que GitHub聽(git, en realidad) es la herramienta b谩sica que todos utilizamos para llevar el control de nuestras versiones de c贸digo y para poder trabajar de forma colaborativa. Algunos todav铆a utilizamos en algunos entornos SVN (sobre todo los que hacemos cosas para WordPress, que en este aspecto sigue un poco en el pasado), y otros han pasado de GitHub a GitLab聽o Bitbucket.

En mi caso, yo me quedo con GitHub para todo lo que sea software libre (todos los repositorios p煤blicos son gratuitos), y con Bitbucket para todo lo que sea privado (hasta 6 usuarios es gratuito). De esta forma, tengo todos los proyectos libres en GitHub, y todo lo relacionado con聽clientes en mi repositorio de Bitbucket. De esta forma puedo tener una copia completa de su sistema, configuraci贸n incluida, y siempre puedo ir hacia adelante y hacia atr谩s en el sistema.

Copias de seguridad con Bitbucket

Adem谩s del trabajo normal y rutinario, donde actualizamos cosas o programamos cosas y las a帽adimos a nuestro git, una de las cosas que tengo automatizadas para todos los clientes son las copias de seguridad. 驴C贸mo las hago?

Aprovechando que Bitbucket no me pone l铆mites a la hora de subir repositorios (aunque me ponga un bonito mensaje grande y amarillo si me paso del giga), lo subo todo ah铆.

Cada 6 horas hago que el sistema ejecute un script con cron job.

sh /home/raven/cronjob.sh > /dev/null 2>&1
sh /home/raven/mysqljob.sh > /dev/null 2>&1

view raw
cron execution
hosted with ❤ by GitHub

Y hago que se haga una copia de seguridad en Bitbucket… (git add –all borrar谩 tambi茅n los archivos que se hayan borrado, y esto es importante para despu茅s).

#!/bin/sh
cd ~/domains/bi0xid.es/public_html/web/
git add –all
git commit -m "copia de seguridad"
git push origin master
cd ~/domains/darkblue.es/public_html/web/
git add –all
git commit -m "copia de seguridad"
git push origin master
[…]

view raw
git push sec-copy
hosted with ❤ by GitHub

… y otra de la base de datos, aunque 茅sta la guardo en local.

mysqldump –single-transaction –user=XXXX –password=XXXX –databases XXXX > /home/raven/backup/incremental/XXXX-$(date +%Y%m%d-%H%M).sql
mysqldump –single-transaction –user=XXXX –password=XXXX –databases XXXX > /home/raven/backup/incremental/XXXX-$(date +%Y%m%d-%H%M).sql

view raw
mysql sec-copy
hosted with ❤ by GitHub

Dando un paso atr谩s con las bases de datos

Imaginaos que un cliente nos llama porque se ha cargado un art铆culo que estaba haciendo ayer. No sabe c贸mo ha pasado, pero el art铆culo se ha ido a la papelera, y la papelera se ha borrado sola. S铆, pasa mucho. M谩s de lo que os imagin谩is. 驴C贸mo solucionamos esto?

Pues tiramos de copia de seguridad. Lanzamos este comando y…

mysql -u usuario -pcontrase帽a base_de_datos < archivo_copia_de_seguridad.sql

view raw
mysql import
hosted with ❤ by GitHub

隆Restaurado!

Pero atenci贸n. Esta copia de la base de datos es una copia聽completa de la base de datos. Si ten茅is algo m谩s que un blog conectado con Jetpack, esto machacar谩 datos de m茅tricas que para vosotros pueden ser muy valiosos. 驴Qu茅 hacemos en ese caso? Pues modificar la copia de seguridad de la base de datos聽que hac铆amos inicialmente, para ajustarla a nuestras necesidades. En el ejemplo ten茅is c贸mo hacer un dump de la base de datos ignorando tablas, o a帽adiendo s贸lo las tablas que queramos.

mysqldump –single-transaction –user=XXXX –password=XXXX –databases XXXX –ignore-table=wp_options > /home/raven/backup/incremental/XXXX-$(date +%Y%m%d-%H%M).sql
mysqldump –single-transaction –user=XXXX –password=XXXX –databases XXXX wp_commentmeta wp_comments wp_postmeta wp_posts wp_term_relationships wp_term_taxonomy wp_terms > /home/raven/backup/incremental/XXXX-$(date +%Y%m%d-%H%M).sql

Lo bueno que tiene este sistema es que nos podemos hacer una copia por cada tabla, o agruparlas de la forma que queramos, para que cualquier restauraci贸n del sistema sea muy sencilla y r谩pida de hacer. Si lo tenemos todo correctamente automatizado, podremos incluso hacerlo desde el m贸vil.

驴Esto sustituye a la copia de seguridad tradicional?

Podr铆a, pero la respuesta es NO.聽Hago hasta tres copias de seguridad de todo, y en alguna ocasi贸n he tenido que tirar de la tercera. Para no hacer una cuarta,聽organic茅 este sistema que me ayuda en el d铆a a d铆a. Pero estamos confiando en un sistema externo, por lo que debe ser una copia m谩s.

Staging con DeployHQ

DeployHQ es un servicio que nos permite conectar un servicio de versionado como GitHub o Bitbucket a una cuenta.

dep1

Una vez conectado, nos mostrar谩 el listado de nuestros repositorios, y podremos elegir cualquiera de ellos.

dep2Y una vez elegido, nos conectar谩 con el servicio creando una nueva clave p煤blica en Github de forma autom谩tica.

dep3

Tras este paso, DeployHQ nos cachear谩 el repositorio. De esta forma, podemos hacer cualquier despliegue en segundos.

Despu茅s a帽adiremos nuestro servidor (que puede ser una conexi贸n por FTP, si estamos trabajando para un cliente externo).

ftp

Y a partir de este momento, ya estaremos preparados para enviar cosas al servidor. Todo lo que est茅 giteado lo podremos mover hacia adelante y hacia atr谩s, y el sistema de DeployHQ nos聽a帽adir谩 o borrar谩 la informaci贸n necesaria correspondiente a nuestro git. Y si ha pasado algo raro, incluso podemos volcar el repositorio completo.

repository

Y la ejecuci贸n es tal que as铆:

deployment

As铆 que tenemos:

  • Copias de seguridad que podemos llevar hacia adelante y hacia atr谩s siempre que necesitemos
  • Una forma de poner en producci贸n cambios, y de revertirlos en seguida en caso de que vayan mal

Si estamos desarrollando en local, en un servidor de desarrollo, o en un directorio del mismo servidor, de esta forma podemos montarnos un sistema de control muy c贸modo e interesante que nos puede ahorrar muchas horas y quebraderos de cabeza.

DeployHQ es gratis para un proyecto. Tambi茅n para proyectos Open Source si hablas con ellos. Y para repositorios privados, 拢6 al mes por 10 repositorios. Un precio m谩s que razonable para tener totalmente atados los proyectos en los que est谩s trabajando.

Ejecutando comandos con DeployHQ

Despu茅s de probar distintos softwares para integraci贸n continua, me decant茅 por DeployHQ por estas razones:

  • Enlaza a tus cuentas existentes en GitHub, GitLab y Bitbucket. No tienes que contar con sus repositorios para funcionar.
  • Su web es totalmente responsive, lo que me permite utilizarla desde el m贸vil sin sufrimiento.
  • Permite conexi贸n con servidores FTP, que es lo m谩s com煤n que vas a tener cuando trabajas con clientes externos que tienen servidores聽reguleros. La mayor铆a de otros servicios de integraci贸n continua funcionan 煤nicamente a trav茅s de git pull/push.
  • Si lo conectamos a trav茅s de SSH, permite la ejecuci贸n de comandos.

S铆. Podemos decirle que ejecute comandos. Antes o despu茅s del despliegue, e incluso en qu茅 despliegues queremos que ocurra.

before

Y podemos crear comandos tan peregrinos como 茅ste:

after

B谩sicamente, nos permite jugar con todo lo que queramos. Si le ponemos un servidor dummy, que no haga ning煤n deploy, tambi茅n podemos utilizarlo para:

  • lanzar copias de seguridad concretas
  • copias a FTP
  • copias a otro servidor
  • sincronizaci贸n de servidores de desarrollo y producci贸n con rsync o scp

Las posibilidades son muy grandes, y es lo que me gusta de haber montado un sistema as铆. S铆, 拢6 al mes. Merecen la pena.

Categor铆as
Tutoriales

Ordenando Gmail: Anular suscripci贸n

Hay una cosa que me encanta de GMail y que quiz谩 no hay谩is visto: el enlace聽de Anular suscripci贸n.

Anular suscripci贸n

Estamos en una de estas 茅pocas en las que los coleccionables por fasc铆culos vuelven a los kioskos. Junto a ellos, te encuentras montones de peticiones de amistad (o lo que sea) de un mont贸n de servicios nuevos en los que tus amigos聽han entrado y han tenido la maravillosa idea de invitar a toda su lista de contactos. Si no han tenido el cuidado suficiente (y normalmente no lo tienen), el sistema no habr谩 consultado s贸lo su base de datos para saber si est谩is en ella. No. Tambi茅n os habr谩 enviado un mensaje invit谩ndoos al servicio y, muy probablemente, os habr谩 suscrito a su lista de correo porque s铆.

Gracias,聽amigos. Os odio profundamente.聽Pero como聽odiando no se vac铆a la el buz贸n de correo, hay que actuar.

Gmail tiene una cosa interesante en la que normalmente no nos fijamos. Si abrimos un correo que procede de una lista, y tiene un bot贸n de desuscribirse, Gmail lo captura y nos lo pone cerca del dedo.

Bot贸n anular suscripci贸n de Gmail

Pinchar en聽Anular suscripci贸n tiene dos ventajas sobre el m茅todo tradicional de ir al final del correo y darle al bot贸n de desuscribirse:

  • Si no necesita confirmaci贸n, Gmail realiza el proceso sin hacerte visitar ninguna otra p谩gina
  • Si llega alg煤n correo posterior, Gmail se encargar谩 de hacer que no lo veas

Muchas veces siguen llegando correos durante unos d铆as porque las newsletters est谩n preparadas con antelaci贸n, por lo que tu baja es efectiva s贸lo para los correos nuevos. Y, otras veces, los servicios se pasan tu desuscripci贸n por ah铆 mismo. As铆 que es un buen sistema para quitarte de encima todos los correos no deseados.

Anular suscripci贸n a Square Enix

B煤squeda avanzada

Gmail tiene otra herramienta interesante para hacer b煤squedas avanzadas de correo. Normalmente, cuando queremos hacer una b煤squeda avanzada en el correo, podemos escribir cosas como

from: midireccion@decorreo.com

y Gmail buscar谩聽todos los correos que vengan de esa direcci贸n de correo.聽Aqu铆 ten茅is la lista de comandos que pod茅is utilizar, que son los que realmente hacen a Gmail 煤til: b煤squedas por fecha, filtros…

Pero a聽lo que vamos. Imaginemos que nos han llegado un pu帽ado de correos de un servicio que no conocemos llamado Brewster, y queremos borrarlos. Una opci贸n ser铆a entrar en nuestro correo, copiar la direcci贸n de la que viene, y utilizar el聽from: que ve铆amos antes para obtener el listado de todos los correos del mismo remitente.

Anular suscripci贸n en Brewster - 1

Anular suscripci贸n en Brewster - 2

De esta forma podremos borrar todos los correos que ese remitente que est茅n en nuestro buz贸n de correo.

Y es m谩s. Lo podemos hacer a煤n m谩s f谩cil. Los chicos de Gmail se han dado cuenta (y muchos usuarios le han dicho a trav茅s del foro para sugerir nuevas cosas a Labs), y nos lo han puesto f谩cil. Cuando pasamos por encima de cualquier correo en la lista general, nos aparece un bot贸n de emails o mensajes, seg煤n el idioma en el que tengamos nuestro Gmail.聽Anular suscripci贸n en Brewster - 3

Si pinchamos sobre el bot贸n, autom谩ticamente nos har谩 la b煤squeda con nuestro聽from: sin que nosotros tengamos que preocuparnos de nada m谩s.

Anular suscripci贸n en Brewster - 4

Con estos dos m茅todos, podemos mantener una bandeja de entrada bastante limpia y ordenada.