File: hello.py

package info (click to toggle)
coot 1.1.18%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 219,964 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (80 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# hello.py
# Copyright 2005, 2006 by Bernhard Lohkamp
# Copyright 2003, 2004, 2005, 2006 Paul Emsley, University of York
# Copyright 2016 by Medical Research Council
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Primarily for Indian Names.
#
# Say we are given str: (list "M." "D." "Albert" "Dorkins").  We want
# to return ""Albert" not "M.")  We reject names that are one
# character long and names that are 2 characters long that end in
# ".".  So, "M." is rejected, but "Ma" is not.
#
# An excercise for the committed is to also reject run-together
# dotted initials such as "D.K.".  I was sufficiently committed.
# BL says: I'll try to too! Although I dont think this is a valuable
# (Win)Coot function, but fun though...
#

import time
import string
import os, sys
import getpass
import coot

def coot_says_hello():

   def first_non_trivial_name(str_list):

       name = "Person with No Name"
       if len(str_list) == 0 : pass
       else:
          for ls in str_list:
             if (not ls.endswith(".") and len(ls)>1):
                name = ls
                break
       return name

   hour = int(time.strftime("%H", time.localtime()))
   if hour < 12: time_str = "Morning"
   elif hour < 18: time_str = "Afternoon"
   else : time_str = "Evening"
   try:

      import pwd
      user = getpass.getuser()
      name_string = pwd.getpwnam(user).pw_gecos
      name_strings = name_string.split()

   except:
      name_string = getpass.getuser()
      name_strings = name_string.split()

   # reverse name_strings if locale is japanese
   l1 = os.getenv("LANG")
   l2 = os.getenv("LANGUAGE")
   if l1 == "ja": name_strings.reverse() # perhaps beginswith
   if l2 == "ja": name_strings.reverse()
   personal_name = str.capitalize(first_non_trivial_name(name_strings))
   hello_str = "Good %s %s, Welcome to Coot version %s" %(time_str, personal_name, coot.coot_version())
   print(hello_str)
   coot.set_display_intro_string(hello_str)

# check for main
#if __name__ == "__main__":

coot_says_hello()