You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-desktop/setup.py

159 lines
5.7 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# setup.py --- Setup script for calculate-client
#Copyright 2010 Calculate Pack, http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import stat
from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.command.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts
__app__ = "calculate-desktop"
__version__ = "2.2.0"
data_files = []
var_data_files = []
data_dirs_template = ['desktop-templates']
data_dirs_share = ['i18n']
share_calculate_dir = "/usr/share/calculate-2.2/"
template_calculate_dir = os.path.join(share_calculate_dir, "templates")
def __scanDir(scanDir, prefix, dirData, flagDir=False):
"""Scan directory"""
files = []
dirs = []
if flagDir or stat.S_ISDIR(os.stat(scanDir)[stat.ST_MODE]):
for fileOrDir in os.listdir(scanDir):
absPath = os.path.join(scanDir,fileOrDir)
statInfo = os.stat(absPath)[stat.ST_MODE]
if stat.S_ISREG(statInfo):
files.append(absPath)
elif stat.S_ISDIR(statInfo):
dirs.append(absPath)
if prefix:
scanDir = os.path.join(prefix,scanDir)
dirData.append((scanDir, files))
for sDir in dirs:
__scanDir(sDir, prefix, dirData, True)
return dirData
def create_data_files(data_dirs, prefix=""):
"""Create data_files"""
data_files = []
for data_dir in data_dirs:
data = []
data_files += __scanDir(data_dir, prefix, data)
return data_files
data_files += create_data_files (data_dirs_template, template_calculate_dir)
data_files += create_data_files (data_dirs_share, share_calculate_dir)
data_files += [('/usr/share/calculate-2.2/xdm', ['data/cmd_login',
'data/functions',
'data/gtkbg',
'data/xdm'])] +\
[('/etc/calculate/xdm/login.d', ['data/login.d/00init',
'data/login.d/20desktop',
'data/login.d/99final'])] +\
[('/etc/calculate/xdm/logout.d', ['data/logout.d/00init'])] +\
[('/var/calculate/templates', [])]
class cl_install_data(install_data):
def run (self):
install_data.run(self)
data_file = [("/usr/share/calculate-2.2/xdm/gtkbg",0755),
("/usr/share/calculate-2.2/xdm/cmd_login",0755),
("/usr/share/calculate-2.2/xdm/xdm",0755)]
fileNames = map(lambda x: os.path.split(x[0])[1], data_file)
listNames = map(lambda x: filter(lambda y: y, x[0].split("/")),data_file)
data_find = {}
for i in range(len(fileNames)):
listNames[i].reverse()
data_find[fileNames[i]] =[listNames[i],data_file[i][1]]
for path in self.get_outputs():
nameFile = os.path.split(path)[1]
if nameFile in data_find.keys():
data = data_find[nameFile][0]
mode = data_find[nameFile][1]
flagFound = True
iMax = len(data)
pathFile = path
for i in range(iMax):
if data[i] != os.path.split(pathFile)[1]:
flagFound = False
break
pathFile = os.path.split(pathFile)[0]
if flagFound:
os.chmod(path, mode)
class cl_build_scripts(build_scripts):
"""Class for build scripts"""
def run (self):
scripts = ['./scripts/install', './scripts/uninstall']
backup_build_dir = self.build_dir
backup_scripts = filter(lambda x: not x in scripts, self.scripts)
self.scripts = scripts
self.build_dir = self.build_dir + "-bin"
build_scripts.run(self)
self.scripts = backup_scripts
self.build_dir = backup_build_dir
build_scripts.run(self)
class cl_install_scripts(install_scripts):
"""Class for install scripts"""
def run (self):
backup_install_dir = self.install_dir
backup_build_dir = self.build_dir
cl_cmd_obj = self.distribution.get_command_obj("install")
self.build_dir = self.build_dir + "-bin"
self.install_dir = os.path.join(cl_cmd_obj.install_platlib, __app__,
"bin")
install_scripts.run(self)
self.build_dir = backup_build_dir
self.install_dir = backup_install_dir
install_scripts.run(self)
setup(
name = __app__,
version = __version__,
description = "Create and configure user profile",
author = "Mir Calculate Ltd.",
author_email = "support@calculate.ru",
url = "http://calculate-linux.org",
license = "http://www.apache.org/licenses/LICENSE-2.0",
package_dir = {'calculate-desktop': "."},
packages = ['calculate-desktop.pym'],
data_files = data_files,
scripts=["./scripts/cl-createhome-2.2",
"./scripts/install",
"./scripts/uninstall"],
cmdclass={'install_data': cl_install_data,
'build_scripts':cl_build_scripts,
'install_scripts':cl_install_scripts},
)