Saturday, February 4, 2017

Changing the root password for MySQL

I need to change my root password on mySQL.

First I get the command line:

mysql -u root -p

It took a while to find, but here's the magic incantation to change the password:

MariaDB [(none)]> set password = password('xxxx')

Sunday, January 29, 2017

Using SQL to build a simple test database

I need a database for my newest python app.

So to test my app, I need to create a test database, and fill it with test data.

As a start, here's the SQL to create a client table, with one field (for now), and insert 3 records into it:

use tempdb;
drop table clients;
create table clients
(
client_name varchar(80)
);
insert into clients values ('client1');
insert into clients values ('client2');
insert into clients values ('client3');

Saturday, January 28, 2017

Logging in to MySQL from a python script

When I try and run my tests, I get this error:

[ed@mikado STC.Sendgrid.Collector]$ bash build.sh
ERROR 1044 (42000) at line 1: Access denied for user ''@'localhost' to database 'tempdb'


I can log in to mySQL on the command line like this:

 sudo mysql --user=root --password=xxxxx tempdb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.1.20-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

This is well-described here.

I want to see what tables are available:

MariaDB [tempdb]> show tables;
show tables;
Empty set (0.00 sec)

No tables, but still, the python script should let me log on.

OK, turns out that my user name and password need to be set as environment vars.

When I try this I get further:

PYTHONPATH=. SG_DB_USER=root SG_DB_PASSWORD=xxxx pytest

Tuesday, December 27, 2016

How to checkout repo contents as it was on a given date in git

A bit tricky, but this does it:

git checkout `git rev-list -n 1 --before="2009-07-27 13:37" master`

Wednesday, December 7, 2016

Strage error with gnupghome parameter for pgp

I am using them pgp module for encryption in a python app.

It runs fine on the customers machine, and also on our cloud-based Jenkins server.

But it fails on my new development machine with:

init() got an unexpected keyword argument 'gnupghome'

This happening in this line of code:

        gpg = gnupg.GPG(gnupghome=self.TMP_DIR + '/pgp')

In a previous version of this code, this was homedir. I am going to try that again.

Monday, October 17, 2016

An Auto-Status Generator for Software Projects

As a software project manager, I often have to create status reports about software projects.

In a good software process, status reports should not really be necessary. The on-line tools, from github to JIRA, can already provide a great deal of really useful information on project progress. But I can never get any of my bosses to ever look at them. ;-)

(I also suspect that they rarely or never look at the status reports, beyond the first sentence.)

So why not have a little python program that will automatically generate my status report?

Here's the requirements:

  • Takes a date and gets git commit comments for that day.
  • Can do whole project or just one user.



Sunday, October 16, 2016

Clearing up Python Import Confusion

Today I got the familiar Import not found error from Python:

ImportError: No module named mime.multipart

This is complaining about an import here:

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

Here's a good way to figure out what went wrong:

Python 2.7.12 (default, Sep 29 2016, 13:30:34)
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
>>> dir(email)
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header', 'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_name', 'base64MIME', 'email', 'importer', 'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys']
>>> dir(email.mime)
['Audio', 'Base', 'Image', 'Message', 'Multipart', 'NonMultipart', 'Text', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
I see from this that I should be importing email.mime.Multipart (not the upper-case M).

But when I try that, it also does not work:

>>> from email.mime.Multipart import MIMEMultipart
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Multipart

Turns out the problem was my module name, email.py. This caused some conflicts in python. I changed it to status_email.py and now everything works.