Question

Here is the situation: the company that I'm working in right now gave me the freedom to work with either java or python to develop my applications. The company has mainly experience in java.

I have decided to go with python, so they where very happy to ask me to give maintenance to all the python projects/scripts related to the database maintenance that they have.

Its not that bad to handle all that stuff and its kind of fun to see how much free time I have compared to java programmers. There is just one but, the projects layout is a mess.

There are many scripts that simply lay in virtual machines all over the company. Some of them have complex functionality that is spread across a few modules(4 at maximum.)

While thinking about it about it, I realized that I don't know how to address that, so here are 3 questions.

  • Where do I put standalone scripts? We use git as our versioning system.
  • How do structure the project's layout in a way that the user do not need to dig deep into the folders to run the programs(in java I created a jar or a jar and a shell script to handle some bootstrap operations.)
  • What is a standard way to create modules that allow easy reusability(mycompany.myapp.mymodule?)
Was it helpful?

Solution

Where do I put standalone scripts?

You organize them "functionally" -- based on what they do and why people use them.

The language (Python vs. Java) is irrelevant.

You have to think of scripts as small applications focused on some need and create appropriate directory structures for that application.

We use /opt/thisapp and /opt/thatapp. If you want a shared mount-point, you might use a different path.

How do structure the project's layout in a way that the user do not need to dig deep into the folders to run the programs

You organize them "functionally" -- based on what they do and why people use them. At the top level of a /opt/thisapp directory, you might have an __init__.py (because it's a package) and perhaps a main.py script which starts the real work.

In Python 2.7 and Python 3, you have the runpy module. With this you would name your top-level main script __main__.py

http://docs.python.org/library/runpy.html#module-runpy

What is a standard way to create modules that allow easy reusability(mycompany.myapp.mymodule?)

Read about packages. http://docs.python.org/tutorial/modules.html#packages

OTHER TIPS

A package is a way of creating a module hierarchy: if you make a file called __init__.py in a directory, Python will treat that directory as a package and allow you to import its contents using dotted imports:

spam \
       __init__.py
       ham.py
       eggs.py

import spam.ham

The modules inside a package can reference each other -- see the docs.

If these are all DB maintenance scripts, I would make a package called DB or something, and place them all in it. You can have subpackages for the more complicated ones. So if you had a script for, I don't know, cleaning up the transaction logs, you could put it in ourDB.clean and do

import ourDB.clean
ourDB.clean.transaction_logs( )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top