Skip to content

Commit

Permalink
move stuff around for easier packaging, introduce setup.py, desktop f…
Browse files Browse the repository at this point in the history
…ile, a temp icon and an appdata file
  • Loading branch information
Toms Bauģis committed Jan 18, 2015
1 parent e7766f1 commit 9572263
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.py[cod]

build/
dist/
apx.egg-info

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added apx/lib/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions scores.py → apx/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,53 @@
# - coding: utf-8 -
# Copyright (C) 2014 Toms Bauģis <toms.baugis at gmail.com>
import datetime as dt
import logging
import sqlite3 as sqlite
import os

from shutil import copy as copyfile


class Storage(object):
def __init__(self):
self._con = None
self.db_path = self.__init_db_file()

def __init_db_file(self):
try:
from xdg.BaseDirectory import xdg_data_home
database_dir = os.path.realpath(os.path.join(xdg_data_home, "apx"))
except ImportError:
print "Could not import xdg - will store apx.sqlite in the home folder"
database_dir = os.path.realpath(os.path.expanduser("~"))

if not os.path.exists(database_dir):
os.makedirs(database_dir, 0744)

# handle the move to xdg_data_home
db_path = os.path.join(database_dir, "apx.sqlite")

# check if we have a database at all
if not os.path.exists(db_path):
# if not there, copy from the defaults
try:
from apx import config
data_dir = os.path.join(config.DATA_DIR)
except ImportError:
# if defs is not there, we are running from sources
module_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(module_dir, '..', 'data')

data_dir = os.path.realpath(data_dir)

logging.info("Database not found in %s - installing default from %s!" % (db_path, data_dir))
copyfile(os.path.join(data_dir, 'apx.sqlite'), db_path)

#change also permissions - sometimes they are 444
os.chmod(db_path, 0664)

return db_path


def get_scores(self):
scores = self.fetch("""select date, name, level, score, duration from scores
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 17 additions & 13 deletions apx.py → bin/apx
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
#!/usr/bin/env python
# - coding: utf-8 -
# Copyright (C) 2013-2014 Toms Bauģis <toms.baugis at gmail.com>
# Copyright (C) 2013-2015 Toms Bauģis <toms.baugis at gmail.com>

import datetime as dt
import itertools
import math
import random
import os, sys

from collections import defaultdict

from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GObject as gobject

try:
import apx
except ImportError:
# when running uninstalled
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from lib import game_utils
from lib import graphics
from lib import utils
from lib import layout
from lib.pytweener import Easing
from apx.lib import game_utils
from apx.lib import graphics
from apx.lib import utils
from apx.lib import layout
from apx.lib.pytweener import Easing

import board
import game
import splash
import screens
import sprites
from apx import board
from apx import game
from apx import splash
from apx import screens
from apx import sprites


class Scene(graphics.Scene):
Expand Down Expand Up @@ -325,8 +331,6 @@ def _on_enter_frame(self, scene, context):
g.fill_stroke("#0f0", "#fff", 0.3)




class BasicWindow(object):
def __init__(self):
self.window = gtk.Window()
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions data/apx.appdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2013 First Lastname <your@email.com> -->
<component type="desktop">
<id>apx.desktop</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>MIT</project_license>
<name>apx</name>
<summary>A playful QIX clone</summary>
<description>
<p>
APX is a QIX clone with minor differences in gameplay from the original.
</p>
<ul>
<li>
Use arrow keys to move around the perimeter of square, hold down Space or Shift
to cut into the area. Connect back to perimeter to claim the area.
</li>
<li>
Your objective is to claim 75% or more to proceed to the next level
</li>
<li>
Claiming with Shift key will be slower but give you double the points.
</li>
<li>
For every claimed full percent over 75% you get extra 1000 points.
</li>
</ul>
</description>
<screenshots>
<screenshot type="default">
<image>https://farm8.staticflickr.com/7434/13823878335_e242ac1c23_o.png</image>
<caption>APX gameplay</caption>
</screenshot>
</screenshots>
<url type="homepage">https://github.com/projecthamster/apx</url>
<updatecontact>toms.baugis@gmail.com</updatecontact>
</component>
9 changes: 9 additions & 0 deletions data/apx.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=APX
Comment=APX - a QIX clone
Icon=/usr/share/apx/icons/apx.svg
Exec=/usr/bin/apx
Categories=GNOME;GTK;Games;
Binary file renamed apx.sqlite → data/apx.sqlite
Binary file not shown.
82 changes: 82 additions & 0 deletions data/apx.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env %{__python2}
# - coding: utf-8 -
import distutils.command.install
import os
import platform
import sys

from setuptools import setup

DATADIR = os.path.join(sys.prefix, "share", "apx")
class install(distutils.command.install.install):

def finalize_options(self):
special_cases = ('debian', 'ubuntu')
if (platform.system() == 'Linux' and
platform.linux_distribution()[0].lower() in special_cases):
# Maintain an explicit install-layout, but use deb by default
specified_layout = getattr(self, 'install_layout', None)
self.install_layout = specified_layout or 'deb'

distutils.command.install.install.finalize_options(self)



setup(
name = "apx",
version = "0.1",
author = "Toms Bauģis",
author_email = "toms.baugis@gmail.com",
description = "A playful QIX clone.",
license = "MIT",
keywords = "game arcade python",
url = "https://github.com/projecthamster/apx",
long_description=open(os.path.join(os.path.dirname(__file__), 'README.md')).read(),
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: X11 Applications :: GTK",
"Intended Audience :: End Users/Desktop",
"Topic :: Games/Entertainment",
"License :: OSI Approved :: MIT License",
],


packages=['apx', 'apx.lib'],
scripts=['bin/apx'],
data_files= [
('share/apx/icons', ['data/apx.svg']),
('share/fonts/04b03', ['data/04b03.ttf', 'data/04b03_LICENSE',]),
('data', ['data/apx.sqlite']),
('share/appdata', ['data/apx.appdata.xml']),
('share/applications', ['data/apx.desktop']),
],

cmdclass={
"install": install,
},
)

0 comments on commit 9572263

Please sign in to comment.